CSS & JavaScript Toolbox - Version 0.8

Version Description

  • Modifying template code.
  • Header and Footer hooks support: Select in which hook to output CSS/JS code.
  • Blocks can be reordered.
  • Blocks can be named.
  • New icons and improved UI.
  • Multilingual support: Only English translation is shipped with this version.
  • Style overriding: Blocks order allow later blocks styles to override former blocks.
  • Embedded Scripts: Embedded WordPress or Scripts that shipped out with CJToolbox Plugin by just checking them.
  • Backup and Restore blocks data.
  • Bug Fix: New blocks not toggling unless the page is refreshed.
  • Bug Fix: CSS/JS template extra slashes problem.
  • Bug Fix: Block deletion issues.
  • Bug Fix: Code is not applied to the URL list except the last URL.
  • Bug Fix: Cannot use string offset as array error.
  • Bug Fix: Invalid argument supplied foreach() error.
Download this release

Release Info

Developer wipeoutmedia
Plugin Icon 128x128 CSS & JavaScript Toolbox
Version 0.8
Comparing to
See all releases

Code changes from version 0.3 to 0.8

Files changed (73) hide show
  1. css-js-toolbox.php +1024 -830
  2. includes/modulebase.inc.php +173 -0
  3. includes/modules.inc.php +142 -0
  4. includes/wpnavmenuwalker.inc.php +64 -0
  5. langs/css-javascript-toolbox.pot +533 -0
  6. media/icons/add_code.png +0 -0
  7. media/icons/delete_code.png +0 -0
  8. media/icons/external_link.gif +0 -0
  9. media/icons/insert_code.png +0 -0
  10. modules/tools/public/css/style.css +9 -0
  11. modules/tools/public/images/link-loading.gif +0 -0
  12. modules/tools/public/js/tools.js +234 -0
  13. modules/tools/tools.php +226 -0
  14. modules/tools/views/backupform.html.tmpl +35 -0
  15. modules/tools/views/tools-bar.html.tmpl +20 -0
  16. modules/v03e/public/css/style.css +34 -0
  17. modules/v03e/public/images/error.png +0 -0
  18. modules/v03e/public/images/warning.png +0 -0
  19. modules/v03e/public/js/edc.js +368 -0
  20. modules/v03e/v03e.php +337 -0
  21. modules/v03e/views/error-note.html.tmpl +40 -0
  22. modules/v03e/views/scan-message.html.tmpl +21 -0
  23. premium-update-check.php +64 -0
  24. {media → public/css}/admin.css +29 -16
  25. public/js/admin.js +426 -0
  26. public/js/contenthash.js +219 -0
  27. public/js/md5-min.js +9 -0
  28. public/js/upload/jquery.cycle.all.min.js +28 -0
  29. public/js/upload/jquery.easing.js +205 -0
  30. {media → public/media}/CSS_JS_Toolbox_Icon.png +0 -0
  31. {media → public/media}/Donate_Button.png +0 -0
  32. {media → public/media}/accept.png +0 -0
  33. {media → public/media}/ajax-loader.gif +0 -0
  34. public/media/icons/add_code.png +0 -0
  35. public/media/icons/delete_code.png +0 -0
  36. public/media/icons/edit_code.png +0 -0
  37. public/media/icons/external_link.png +0 -0
  38. public/media/icons/insert_code.png +0 -0
  39. {media → public/media}/icons/insert_code1.png +0 -0
  40. {media → public/media}/index.php +0 -0
  41. {media → public/media}/loading-bottom.gif +0 -0
  42. public/media/upload/.htaccess +3 -0
  43. public/media/upload/index.php +3 -0
  44. public/media/upload/latestversion.png +0 -0
  45. {media → public/media}/warning.png +0 -0
  46. readme.txt +111 -49
  47. screenshot-1.jpg +0 -0
  48. screenshot-1.png +0 -0
  49. screenshot-10.jpg +0 -0
  50. screenshot-11.jpg +0 -0
  51. screenshot-2.jpg +0 -0
  52. screenshot-2.png +0 -0
  53. screenshot-3.jpg +0 -0
  54. screenshot-3.png +0 -0
  55. screenshot-4.jpg +0 -0
  56. screenshot-4.png +0 -0
  57. screenshot-5.jpg +0 -0
  58. screenshot-5.png +0 -0
  59. screenshot-6.jpg +0 -0
  60. screenshot-6.png +0 -0
  61. screenshot-7.jpg +0 -0
  62. screenshot-8.jpg +0 -0
  63. screenshot-9.jpg +0 -0
  64. views/.htaccess +3 -0
  65. views/index.php +0 -0
  66. views/manage.html +79 -0
  67. views/snippets/README.txt +2 -0
  68. views/snippets/block.tmpl +97 -0
  69. views/snippets/blockname.html.tmpl +23 -0
  70. views/snippets/newblock.html.tmpl +6 -0
  71. views/snippets/newcode.html.tmpl +31 -0
  72. views/snippets/scripts.html.tmpl +37 -0
  73. views/snippets/wpobjectslist.tmpl +47 -0
css-js-toolbox.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /*
3
  Plugin Name: CSS & JavaScript Toolbox
4
- Plugin URI: http://wipeoutmedia.com/whats-new/css-javascript-toolbox/
5
  Description: WordPress plugin to easily add custom CSS and JavaScript to individual pages
6
- Version: 0.3
7
  Author: Wipeout Media
8
- Author URI: http://wipeoutmedia.com/whats-new/css-javascript-toolbox/
9
 
10
  Copyright (c) 2011, Wipeout Media.
11
 
@@ -25,790 +25,1000 @@
25
  */
26
 
27
 
28
- //avoid direct calls to this file where wp core files not present
 
 
29
  if (!function_exists ('add_action')) {
30
  header('Status: 403 Forbidden');
31
  header('HTTP/1.1 403 Forbidden');
32
  exit();
33
  }
34
 
35
- define('CJTOOLBOX_VERSION', '0.2');
36
- define('CJTOOLBOX_PATH', plugin_basename( dirname(__FILE__) ));
37
- define('CJTOOLBOX_URL', WP_PLUGIN_URL . '/' . plugin_basename( dirname(__FILE__) ) . '/' );
38
-
39
- if( !class_exists('cssJSToolbox') ) {
40
- class cssJSToolbox {
41
- var $settings = array();
42
- var $settings_name;
43
- var $cjdata = array();
44
- var $cjdata_name;
45
-
46
- function __construct() {
47
-
48
- $this->settings_name = 'cjtoolbox_settings';
49
- $this->cjdata_name = 'cjtoolbox_data';
50
-
51
- // Load saved settings
52
- $this->getSettings();
53
-
54
- // Start this plugin once all other plugins are fully loaded
55
- add_action( 'plugins_loaded', array(&$this, 'start_plugin') );
56
- }
57
-
58
- function __destruct() {
59
- // Nothing to do now...
60
- }
61
-
62
- // Save new settings
63
- function saveSettings() {
64
- update_option($this->settings_name, $this->settings);
65
- }
66
-
67
- // Get back all saved settings
68
- function getSettings() {
69
- $this->settings = get_option($this->settings_name);
70
- }
71
-
72
- // Save/Get data
73
- function saveData() {
74
- $this->cjdata = array_values($this->cjdata);
75
- update_option($this->cjdata_name, $this->cjdata);
76
- }
77
- function getData() {
78
- $this->cjdata = get_option($this->cjdata_name);
79
- }
80
-
81
- function start_plugin() {
82
- if (is_admin() ) {
83
- // Load for admin panel
84
- add_action('admin_menu', array(&$this, 'add_plugin_menu'));
85
- //register the callback been used if options of page been submitted and needs to be processed
86
- add_action('admin_post_save_cjtoolbox', array(&$this, 'on_save_changes'));
87
- // register ajax save function
88
- add_action('wp_ajax_cjtoolbox_save', array(&$this, 'ajax_save_changes'));
89
- add_action('wp_ajax_cjtoolbox_save_newcode', array(&$this, 'ajax_save_newcode'));
90
- add_action('wp_ajax_cjtoolbox_form', array(&$this, 'ajax_show_form'));
91
- add_action('wp_ajax_cjtoolbox_get_code', array(&$this, 'ajax_get_code'));
92
- add_action('wp_ajax_cjtoolbox_delete_code', array(&$this, 'ajax_delete_code'));
93
- add_action('wp_ajax_cjtoolbox_add_block', array(&$this, 'ajax_add_block'));
94
- // Create the tables and sample data
95
- } else {
96
- // Add the script and style files to footer
97
- add_action('wp_head', array(&$this, 'cjtoolbox_insertcode'));
98
- }
99
- }
100
-
101
- function cjtoolbox_insertcode() {
102
- global $post;
103
- // Home page displays a page.
104
- $check_for = '';
105
- if(is_home()) { // The blog page. It will be either same as front page or will be a page.
106
- $check_for = 'allposts';
107
- }
108
- if(is_front_page()) {
109
- $check_for = 'frontpage';
110
- }
111
- if(is_page()) {
112
- $check_for = $post->ID;
113
- }
114
- if(is_single()) {
115
- $check_for = 'allposts';
116
- }
117
-
118
- $this->getData();
119
-
120
- $data = $this->cjdata;
121
- foreach($data as $key => $value) {
122
- $page_list = $data[$key]['page'];
123
- if(is_array($page_list)) {
124
- if(is_page() && in_array('allpages', $page_list)) {
125
- echo stripslashes($data[$key]['code']);
126
- continue;
127
- } else if(in_array($check_for, $page_list)) {
128
- echo stripslashes($data[$key]['code']);
129
- continue;
130
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
132
- if(is_category()) {
133
- $this_category = get_query_var('cat');
134
- $category_list = $data[$key]['category'];
135
- if(is_array($category_list)) {
136
- if(in_array($this_category, $category_list)) {
137
- echo stripslashes($data[$key]['code']);
138
- continue;
139
- }
140
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
- $pageURL = 'http';
144
- if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
145
- $pageURL .= "://";
146
- if ($_SERVER["SERVER_PORT"] != "80") {
147
- $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
148
- } else {
149
- $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
150
- }
151
- $links = stripslashes($data[$key]['links']);
152
- $link_list = explode("\n", $links);
153
- if(in_array($pageURL, $link_list)) {
154
- echo stripslashes($data[$key]['code']);
155
- continue;
156
- }
157
- }
158
- }
159
-
160
- // To add sub page & meta boxes
161
- function add_plugin_menu() {
162
- $this->hook_manage = add_options_page('CSS & JavaScript Toolbox' ,'CSS & JavaScript Toolbox', '10', 'cjtoolbox', array(&$this, 'admin_display'));
163
- // register callback gets call prior your own page gets rendered
164
- add_action('load-'.$this->hook_manage, array(&$this, 'admin_load_page'));
165
-
166
- // register callback to show styles needed for the admin page
167
- add_action( 'admin_print_styles-' . $this->hook_manage, array(&$this, 'admin_print_styles') );
168
- // Load scripts for admin panel working
169
- add_action('admin_print_scripts-' . $this->hook_manage, array(&$this, 'admin_print_scripts'));
170
- }
171
-
172
- //will be executed if wordpress core detects this page has to be rendered
173
- function admin_load_page() {
174
- //ensure, that the needed javascripts been loaded to allow drag/drop, expand/collapse and hide/show of boxes
175
- wp_enqueue_script('common');
176
- wp_enqueue_script('wp-lists');
177
- wp_enqueue_script('postbox');
178
- wp_enqueue_script('thickbox');
179
- wp_enqueue_script('jquery-ui-tabs');
180
-
181
- //add several metaboxes now, all metaboxes registered during load page can be switched off/on at "Screen Options" automatically, nothing special to do therefore
182
- // add_meta_box('cjtoolbox-contentbox-1', 'CSS & JavaScript Block 1', array(&$this, 'on_contentbox_1_content'), $this->hook_manage, 'normal', 'core');
183
- }
184
-
185
- // Apply our stylesheet
186
- function admin_print_styles() {
187
- wp_enqueue_style('thickbox');
188
- wp_enqueue_style( 'cjtoolbox', CJTOOLBOX_URL . 'media/admin.css', '', CJTOOLBOX_VERSION, 'all' );
189
- }
190
-
191
- // Add javascripts
192
- function admin_print_scripts() {
193
- wp_enqueue_style('jquery');
194
- wp_print_scripts('jquery');
195
- ?>
196
- <script type="text/javascript" >
197
- jQuery(document).ready(function($) {
198
- jQuery('form#cjtoolbox_form').submit(function() {
199
- var data = jQuery(this).serialize();
200
- jQuery('#cj-ajax-load').fadeIn();
201
- jQuery.post(ajaxurl, data, function(response) {
202
- var success = jQuery('#cj-popup-save');
203
- var loading = jQuery('#cj-ajax-load');
204
- loading.fadeOut();
205
- success.fadeIn();
206
- window.setTimeout(function(){
207
- success.fadeOut();
208
- }, 3000);
209
- });
210
- return false;
211
- });
212
-
213
- //Update Message popup
214
- jQuery.fn.center = function () {
215
- this.animate({"top":( jQuery(window).height() - this.height() - 200 ) / 2+jQuery(window).scrollTop() + "px"}, 50);
216
- this.animate({"left":( jQuery(window).width() - this.width() - 200 ) / 2 + "px"}, 50);
217
- return this;
218
- }
219
-
220
- // Update loading
221
- jQuery.fn.loadingcenter = function () {
222
- this.animate({"top":( jQuery(window).height() - this.height() - 60 ) / 2 + jQuery(window).scrollTop() + "px"}, 50);
223
- this.animate({"left":( jQuery(window).width() - this.width() - 60 ) / 2 + "px"}, 50);
224
- return this;
225
- }
226
-
227
-
228
- jQuery('#cj-popup-save').center();
229
- jQuery('#cj-popup-reset').center();
230
- jQuery('#cj-ajax-load img').loadingcenter();
231
- jQuery(window).scroll(function() {
232
- jQuery('#cj-popup-save').center();
233
- jQuery('#cj-popup-reset').center();
234
- jQuery('#cj-ajax-load img').loadingcenter();
235
- });
236
-
237
- jQuery('#cjtoolbox-addblock').click(function(e) {
238
- var count = jQuery('#cjblock-count').val();
239
- var security = jQuery('#cjsecurity').val();
240
- var data = {
241
- action : 'cjtoolbox_add_block',
242
- count : count,
243
- security : security,
244
- };
245
- jQuery('#cj-ajax-load').fadeIn();
246
- jQuery.post(ajaxurl, data, function(response) {
247
- var loading = jQuery('#cj-ajax-load');
248
- loading.fadeOut();
249
- if(response == '' || response == 0) {
250
- alert('Oops, unable to add CSS & JavaScript Block! Please try again!!!');
251
- } else {
252
- jQuery('#normal-sortables').append(response);
253
- jQuery(".meta-box-sortables").sortable('refresh');
254
- jQuery('#cjblock-count').val(parseInt(jQuery('#cjblock-count').val()) + 1);
255
- }
256
- });
257
- return false; // For link to behave inactive
258
- });
259
-
260
- });
261
-
262
- function insert_code(type, id) {
263
- var cid = jQuery('#cjtoolbox-'+type+'-'+id+ ' option:selected').val();
264
- var security = jQuery('#cjsecurity').val();
265
- var data = {
266
- action : 'cjtoolbox_get_code',
267
- type : type,
268
- id : cid,
269
- security : security,
270
- };
271
- jQuery('#cj-ajax-load').fadeIn();
272
- jQuery.post(ajaxurl, data, function(response) {
273
- var loading = jQuery('#cj-ajax-load');
274
- loading.fadeOut();
275
- if(response == '' || response == 0) {
276
- alert('Oops, unable to fetch selected '+type+' template! Please try again!!!');
277
- } else {
278
- jQuery('#cjcode-'+id).insertAtCaret(response);
279
- }
280
- });
281
- return false; // For link to behave inactive
282
- }
283
 
284
- function delete_code(type, id) {
285
- var sure = confirm('Are you sure? Selected template will be deleted permanently!!!');
286
- if(!sure) return false;
287
-
288
- var cid = jQuery('#cjtoolbox-'+type+'-'+id+ ' option:selected').val();
289
- var security = jQuery('#cjsecurity').val();
290
- var data = {
291
- action : 'cjtoolbox_delete_code',
292
- type : type,
293
- id : cid,
294
- security : security,
295
- };
296
- jQuery('#cj-ajax-load').fadeIn();
297
- jQuery.post(ajaxurl, data, function(response) {
298
- var loading = jQuery('#cj-ajax-load');
299
- loading.fadeOut();
300
- if(response == '' || response == 0) {
301
- alert('Oops, unable to delete selected '+type+' template! Please try again!!!');
302
- } else {
303
- alert('Selected '+type+' template deleted successfully!');
304
- jQuery('.cjtoolbox-'+type).each(function() {
305
- jQuery(this).find('option[value='+cid+ ']').remove();
306
- });
307
- }
308
- });
309
- return false; // For link to behave inactive
310
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
 
312
- function delete_block(id) {
313
- var sure = confirm('Are you sure?');
314
- if(sure) {
315
- jQuery('#cjtoolbox-'+id).remove();
316
- alert('Please make sure to click "Save All Changes" to delete the block permanently!');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
 
318
- // Reduce total block count by 1 NOTE: Not used now.
319
- // jQuery('#cjblock-count').val(parseInt(jQuery('#cjblock-count').val()) - 1);
320
- }
321
- return false; // For link to behave inactive
322
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
323
 
324
- jQuery.fn.extend({
325
- insertAtCaret: function(myValue){
326
- return this.each(function(i) {
327
- if (document.selection) {
328
- this.focus();
329
- sel = document.selection.createRange();
330
- sel.text = myValue;
331
- this.focus();
332
- }
333
- else if (this.selectionStart || this.selectionStart == '0') {
334
- var startPos = this.selectionStart;
335
- var endPos = this.selectionEnd;
336
- var scrollTop = this.scrollTop;
337
- this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
338
- this.focus();
339
- this.selectionStart = startPos + myValue.length;
340
- this.selectionEnd = startPos + myValue.length;
341
- this.scrollTop = scrollTop;
342
- } else {
343
- this.value += myValue;
344
- this.focus();
345
- }
346
- })
347
- }
348
- });
349
-
350
- </script>
351
- <script type="text/javascript">
352
- jQuery(document).ready(function($) {
353
- $('#cjtoolbox_newcode').live('submit',
354
- function (event) {
355
- event.preventDefault();
356
- var title = $('#cjtoolbox_newcode #new_title').val();
357
- var code = $('#cjtoolbox_newcode #new_code').val();
358
- var type = $('#cjtoolbox_newcode #new_type').val();
359
- var security = $('#cjtoolbox_newcode #new_security').val();
360
- if(title == '') { alert('Please enter title for code!'); return false; }
361
- if(code == '') { alert('Please enter code to save!'); return false; }
362
-
363
- var data = {
364
- action : 'cjtoolbox_save_newcode',
365
- type : type,
366
- title : title,
367
- code : code,
368
- security : security,
369
- };
370
- jQuery('#cjtoolbox_popup .ajax-loading-img').fadeIn();
371
- jQuery.post(ajaxurl, data, function(response) {
372
- var loading = jQuery('#cjtoolbox_popup .ajax-loading-img');
373
- var lastid = parseInt(response);
374
- loading.fadeOut();
375
- if(lastid > 0) {
376
- alert('New code saved successfully!!!');
377
- jQuery('.cjtoolbox-'+type).each(function() {
378
- jQuery(this).append( '<option value="'+lastid+'">'+title+'</option>' );
379
- });
380
- } else {
381
- alert('ISSUE: '+response);
382
  }
383
- tb_remove();
384
- });
385
- return false;
386
- });
387
- });
388
-
389
- </script>
390
- <?php
391
- }
392
-
393
- // Display the admin page for all options
394
- function admin_display() {
395
- $this->getData();
396
- $count = count($this->cjdata);
 
397
 
398
- /** RESET the metabox order to normal, we dont want to retain the order now. Just boxes with data are sufficient.*/
399
- $page = $this->hook_manage;
400
- $neworder = array();
401
- for($i = 1; $i <= $count; $i++) {
402
- $neworder[] = 'cjtoolbox-' . $i;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
403
  }
404
- $order['normal'] = implode(',', $neworder);
405
- $user = wp_get_current_user();
406
- update_user_option($user->ID, "meta-box-order_$page", $order, true);
407
- /*Block END*/
408
 
409
- if($count <= 0) $count = 1; // Atleast have one block by default.
410
- for($i = 1; $i <= $count; $i++) {
411
- add_meta_box('cjtoolbox-'.$i, 'CSS & JavaScript Block #'.$i, array(&$this, 'cjtoolbox_unit'), $this->hook_manage, 'normal', 'core', $i - 1);
 
 
 
 
 
 
412
  }
413
 
414
- echo '<div id="cjtoolbox-admin" class="wrap">';
415
- echo '<div id="custom-icon" style="background: transparent url(\''. CJTOOLBOX_URL . '/media/CSS_JS_Toolbox_Icon.png\') no-repeat;" class="icon32"><br /></div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
416
 
417
- switch ($_GET['page']){
418
- case 'cjtoolbox':
419
- default:
420
- echo '<h2>CSS & JavaScript Toolbox</h2>';
421
- $this->cjtoolbox_manage();
422
- break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
423
  }
424
 
425
- echo '</div>';
426
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
427
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
428
 
429
- // Display the admin page to manage custom css and javscripts
430
- function cjtoolbox_manage() {
431
- $this->getData();
432
- $count = count($this->cjdata);
 
 
 
 
 
 
 
 
 
 
 
433
 
434
- /*
435
- print_r($this->cjdata);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
 
437
- echo "<pre>";
438
- $page = $this->hook_manage;
439
- $sorted = get_user_option( "meta-box-order_$page" );
440
- print_r($sorted);
441
- echo "</pre>";
442
- */
443
- ?>
444
-
445
- <div id="cjtoolbox_donate">
446
- Like this plugin? Please support our work
447
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
448
- <input type="hidden" name="cmd" value="_s-xclick">
449
- <input type="hidden" name="hosted_button_id" value="VMXTA3838F6A8">
450
- <input type="image" src="<?php echo CJTOOLBOX_URL;?>/media/Donate_Button.png" border="0" name="submit" alt="Donate!">
451
- <img alt="" border="0" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1">
452
- </form>
453
- </div>
454
- <div class="cj-save-popup" id="cj-popup-save">
455
- <div id="cj-save-save">Options Updated</div>
456
- </div>
457
- <div class="cj-save-popup" id="cj-popup-reset">
458
- <div id="cj-save-reset">Options Reset</div>
459
- </div>
460
- <div id="cj-ajax-load">
461
- <img src="<?php echo CJTOOLBOX_URL; ?>/media/ajax-loader.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="Working..." />
462
- </div>
463
-
464
-
465
- <form id="cjtoolbox_form" action="admin-post.php" method="post">
466
- <?php wp_nonce_field('cjtoolbox'); ?>
467
- <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
468
- <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>
469
- <input type="hidden" name="action" value="cjtoolbox_save" />
470
- <input type="hidden" id="cjsecurity" name="security" value="<?php echo wp_create_nonce('cjtoolbox-admin');?>" />
471
- <input type="hidden" id="cjblock-count" name="count" value="<?php echo $count; ?>" />
472
- <div id="poststuff" class="metabox-holder">
473
- <div id="post-body">
474
- <?php do_meta_boxes($this->hook_manage, 'normal', $this->cjdata); ?>
475
- </div>
476
- <br class="clear"/>
477
- <div id="save_bar">
478
- <a class="button-secondary" id="cjtoolbox-addblock">Add New CSS/JS Block</a>
479
- <input type="submit" value="Save All Changes" class="button-primary" name="save" />
480
- </div>
481
- </div>
482
- </form>
483
-
484
- <div id="cjtoolbox-tips">
485
- <ul>
486
- <li>Note: CSS &amp; JavaScript Blocks with EMPTY code will not be saved!</li>
487
- <li><b>Warning!</b> Please make sure to validate added CSS &amp; JavaScript codes, the plugin doesn't do that for you!</li>
488
- </ul>
489
- </div>
490
- <script type="text/javascript">
491
- //<![CDATA[
492
- jQuery(document).ready( function($) {
493
- // close postboxes that should be closed
494
- $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
495
- // postboxes setup
496
- postboxes.add_postbox_toggles('<?php echo $this->hook_manage; ?>');
497
- });
498
- //]]>
499
- </script>
500
- <?php
501
- }
502
-
503
-
504
- function cjtoolbox_unit($data = '', $arg = '') {
505
- $boxid = -1; // Because block 1 might have some content...
506
- if($arg != '') {
507
- $boxid = $arg['args'];
508
- }
509
- $this->getData();
510
-
511
- ?>
512
-
513
- <div class="cjpageblock">
514
- <?php $this->show_page_list($boxid, $this->cjdata[$boxid]['page'], $this->cjdata[$boxid]['category']); ?>
515
- <div style="clear:both;"></div>
516
- </div>
517
- <div class="cjcontainer">
518
- <div class="cjcodeblock">
519
- <div class="cssblock">
520
- <p class="cjtitle">CSS Template <?php $this->show_dropdown_box('css', $boxid);?></p>
521
- <p class="cjbutton"><a class="insert_code" title="Insert selected CSS Template" href="#" onclick="return insert_code('css', '<?php echo $boxid;?>');">Insert Code</a> <a class="delete_code" title="Delete selected CSS Template" href="#" onclick="return delete_code('css', '<?php echo $boxid;?>');">Delete Code</a> <a class="add_code thickbox" href="<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php?action=cjtoolbox_form&type=css&width=500&height=350" title="Add New CSS Code Template">New</a></p>
522
- </div>
523
- <div class="jsblock">
524
- <p class="cjtitle">JS Template <?php $this->show_dropdown_box('js', $boxid);?></p>
525
- <p class="cjbutton"><a class="insert_code" title="Insert selected JavaScript Template" href="#" onclick="return insert_code('js', '<?php echo $boxid;?>');">Insert Code</a> <a class="delete_code" title="Delete selected JavaScript Template" href="#" onclick="return delete_code('js', '<?php echo $boxid;?>');">Delete Code</a> <a class="add_code thickbox" href="<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php?action=cjtoolbox_form&type=js&width=500&height=350" title="Add New JavaScript Code Template">New</a></p>
526
- </div>
527
- <div class="datablock">
528
- <textarea cols="100" rows="12" name="cjtoolbox[<?php echo $boxid;?>][code]" id="cjcode-<?php echo $boxid;?>"><?php echo stripslashes($this->cjdata[$boxid]['code']);?></textarea>
529
- </div>
530
- </div>
531
- </div>
532
- <div class="deleteblock">
533
- <p class="cjexample">Click for <a target="_blank" href="http://wipeoutmedia.com/wordpress-plugins/css-javascript-toolbox/" title="Click for Hints &amp; Tips"><strong>Hints &amp; Tips</strong></a></p>
534
- <a class="button-secondary" href="#" onclick="return delete_block('<?php echo ($boxid + 1);?>');">Delete This Block</a>
535
- <div style="clear:both;"></div>
536
- </div>
537
-
538
- <?php
539
- }
540
-
541
-
542
- function show_page_list($boxid, $pages, $categories) {
543
- ?>
544
- <script type="text/javascript">
545
- jQuery(function() {
546
- jQuery( "#tabs-<?php echo $boxid;?>" ).tabs();
547
- });
548
- </script>
549
- <div id="tabs-<?php echo $boxid;?>">
550
- <ul>
551
- <li><a href="#tabs-<?php echo $boxid;?>-1">Pages</a></li>
552
- <li><a href="#tabs-<?php echo $boxid;?>-2">Categories</a></li>
553
- <li><a href="#tabs-<?php echo $boxid;?>-3">URL List</a></li>
554
- </ul>
555
-
556
- <div id="tabs-<?php echo $boxid;?>-1">
557
- <p>Add this CSS/JS code to ?</p>
558
- <ul class="pagelist">
559
- <li><label><input type="checkbox" name="cjtoolbox[<?php echo $boxid;?>][page][]" value="frontpage" <?php echo (is_array($pages) && in_array('frontpage', $pages)) ? 'checked="checked"' : ''; ?> /> Front Page</label> <a class="l_ext" target="_blank" href="<?php bloginfo('url');?>"></a></li>
560
- <li><label><input type="checkbox" name="cjtoolbox[<?php echo $boxid;?>][page][]" value="allposts" <?php echo (is_array($pages) && in_array('allposts', $pages)) ? 'checked="checked"' : ''; ?> /> All Posts</label></li>
561
- <li><label><input type="checkbox" name="cjtoolbox[<?php echo $boxid;?>][page][]" value="allpages" <?php echo (is_array($pages) && in_array('allpages', $pages)) ? 'checked="checked"' : ''; ?> /> All Pages</label></li>
562
- <?php $this->show_pages_with_checkbox($boxid, $pages); ?>
563
- </ul>
564
- </div>
565
- <div id="tabs-<?php echo $boxid;?>-2">
566
- <p>Add this CSS/JS code to category page?</p>
567
- <ul class="pagelist">
568
- <?php $this->show_taxonomy_with_checkbox($boxid, $categories); ?>
569
- </ul>
570
- </div>
571
- <div id="tabs-<?php echo $boxid;?>-3" class="linklist">
572
- <p>Add one URL per line (include http://)</p>
573
- <textarea cols="31" rows="9" name="cjtoolbox[<?php echo $boxid;?>][links]" id="cjcode-links-<?php echo $boxid;?>"><?php echo stripslashes($this->cjdata[$boxid]['links']);?></textarea>
574
- </div>
575
-
576
- </div>
577
- <?php
578
- }
579
-
580
-
581
- // Copied from nav menu feature of WordPress
582
- function show_taxonomy_with_checkbox($boxid, $taxonomy_selected) {
583
- $taxonomy_name = 'category';
584
- $args = array(
585
- 'child_of' => 0,
586
- 'exclude' => '',
587
- 'hide_empty' => false,
588
- 'hierarchical' => 1,
589
- 'include' => '',
590
- 'include_last_update_time' => false,
591
- 'number' => 9999,
592
- 'order' => 'ASC',
593
- 'orderby' => 'name',
594
- 'pad_counts' => false,
595
- );
596
-
597
- $terms = get_terms( $taxonomy_name, $args );
598
-
599
- if ( ! $terms || is_wp_error($terms) ) {
600
- // No items
601
- return;
602
- }
603
 
604
- $db_fields = false;
605
- if ( is_taxonomy_hierarchical( $taxonomy_name ) ) {
606
- $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' );
607
- }
608
-
609
- $walker = new cj_Walker_Nav_Menu_Checklist( $db_fields, $boxid, 'category', $taxonomy_selected );
610
- $args['walker'] = $walker;
611
-
612
- echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $terms), 0, (object) $args );
613
- }
614
-
615
- function show_pages_with_checkbox($boxid, $pages_selected) {
616
-
617
- $post_type_name = 'page';
618
- $args = array(
619
- 'order' => 'ASC',
620
- 'orderby' => 'title',
621
- 'posts_per_page' => 9999,
622
- 'post_type' => $post_type_name,
623
- 'suppress_filters' => true,
624
- 'update_post_term_cache' => false,
625
- 'update_post_meta_cache' => false
626
- );
627
-
628
- // @todo transient caching of these results with proper invalidation on updating of a post of this type
629
- $get_posts = new WP_Query;
630
- $posts = $get_posts->query( $args );
631
- if ( ! $get_posts->post_count ) {
632
- // No items
633
- return;
634
- }
635
-
636
- $db_fields = false;
637
- if ( is_post_type_hierarchical( $post_type_name ) ) {
638
- $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
639
- }
640
-
641
- $walker = new cj_Walker_Nav_Menu_Checklist( $db_fields, $boxid, 'page', $pages_selected );
642
- $post_type_object = get_post_type_object($post_type_name);
643
-
644
- $args['walker'] = $walker;
645
-
646
- $checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
647
- echo $checkbox_items;
648
- }
649
-
650
- //executed if the post arrives initiated by pressing the submit button of form
651
- function on_save_changes() {
652
- //user permission check
653
- if ( !current_user_can('manage_options') )
654
- wp_die( __('Cheatin&#8217; uh?') );
655
- //cross check the given referer
656
- check_admin_referer('cjtoolbox');
657
-
658
- // TODO: This is not coded now because we use AJAX. Should be coded to make the plugin work even if javascript is disabled.
659
- //process here your on $_POST validation and / or option saving
660
- //print_r($_POST);
661
- //die();
662
-
663
- //lets redirect the post request into get request (you may add additional params at the url, if you need to show save results
664
- wp_redirect(add_query_arg( array('updated' => 'true'), $_POST['_wp_http_referer']));
665
- }
666
-
667
-
668
- function ajax_add_block() {
669
- check_ajax_referer('cjtoolbox-admin', 'security');
670
- $count = (int) $_POST['count'];
671
- if($count == 0) $count = 1;
672
- $args = array();
673
- $args['args'] = $count;
674
- ?>
675
- <div id="cjtoolbox-<?php echo $count+1; ?>" class="postbox">
676
- <div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span>CSS & JavaScript Block #<?php echo $count+1; ?></span></h3>
677
- <div class="inside">
678
- <?php $this->cjtoolbox_unit('', $args); ?>
679
- </div>
680
- </div>
681
- <?php
682
- die();
683
- }
684
-
685
- function ajax_save_newcode() {
686
- check_ajax_referer('cjtoolbox-popup', 'security');
687
-
688
- // Add new row to cjdata table
689
- $type = $_POST['type'];
690
- $title = $_POST['title'];
691
- $code = $_POST['code'];
692
- $response = $this->add_cjdata($type, $title, $code);
693
- if($response != false) {
694
- die($response);
695
  }
696
- die('Oops, unable to save '.$type.' code template! Please try again!!!');
697
- }
698
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
699
 
700
- function ajax_save_changes() {
 
 
 
 
 
 
 
 
 
 
 
 
 
701
 
702
- check_ajax_referer('cjtoolbox-admin', 'security');
703
- if($_POST['action'] == 'cjtoolbox_save') {
704
- // Save data and return 1 on success
705
- $cjdata = $_POST['cjtoolbox'];
706
- foreach($cjdata as $key => $value) {
707
- if($value['code'] == '') {
708
- unset($cjdata[$key]);
709
- }
 
 
 
 
 
 
 
 
 
 
710
  }
711
- $this->cjdata = $cjdata;
712
- $this->saveData();
713
- return 1; die('1');
714
- }
715
- return 0; // Something wrong!
716
- die(); // this is required to return a proper result
717
- }
718
-
719
- function ajax_delete_code() {
720
- check_ajax_referer('cjtoolbox-admin', 'security');
721
- $type = $_POST['type'];
722
- $id = (int) $_POST['id'];
723
- if($id <=0 || ($type != 'js' && $type != 'css')) return 'Invalid Request: Unable to process the request!';
724
-
725
- $this->delete_cjdata($type, $id);
726
- die('1');
727
- }
728
-
729
- function ajax_get_code() {
730
- check_ajax_referer('cjtoolbox-admin', 'security');
731
- $type = $_POST['type'];
732
- $id = (int) $_POST['id'];
733
- if($id <=0 || ($type != 'js' && $type != 'css')) return 'Invalid Request: Unable to process the request!';
734
-
735
- $code = $this->get_cjdata($type, $id);
736
- die($code);
737
- }
738
-
739
- function ajax_show_form() {
740
- $type = '';
741
- switch($_GET['type']) {
742
- case 'js':
743
- $type = 'js';
744
- break;
745
- case 'css':
746
- default:
747
- $type = 'css';
748
- break;
749
- }
750
- ?>
751
- <div id="cjtoolbox_popup">
752
- <form id="cjtoolbox_newcode" action="admin-post.php" method="post">
753
- <input id="new_type" type="hidden" name="new_type" value="<?php echo $type;?>" />
754
- <input id="new_security" type="hidden" name="security" value="<?php echo wp_create_nonce('cjtoolbox-popup');?>" />
755
- <p><label>Title <input type="text" id="new_title" name="new_title" value="" size="59" /></label></p>
756
- <p><label>Code <textarea cols="57" id="new_code"rows="9" name="new_code"></textarea></label></p>
757
- <input type="submit" name="submit" value="Save Code Template" />
758
- <img style="display:none;" src="<?php echo CJTOOLBOX_URL; ?>/media/loading-bottom.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="Working..." />
759
- </form>
760
- </div>
761
- <?php
762
- die();
763
- }
764
-
765
- function show_dropdown_box($type, $boxid) {
766
- global $wpdb;
767
-
768
- $query = $wpdb->prepare("SELECT id, title FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '{$type}'");
769
- $list = $wpdb->get_results($query);
770
- if(count($list)) {
771
- echo '<select id="cjtoolbox-'.$type.'-'.$boxid.'" class="cjtoolbox-'.$type.'">';
772
- foreach($list as $def) {
773
- echo '<option value="' . $def->id . '">'. $def->title . '</option>';
774
- }
775
- echo '</select>';
776
- }
777
- }
778
-
779
- function add_cjdata($type, $title, $code) {
780
- global $wpdb;
781
-
782
- if($type == '' || $title == '' || $code == '') return false;
783
- $query = $wpdb->prepare("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('%s', '%s', '%s')", $type, $title, $code);
784
- $wpdb->query($query);
785
- // Get inserted id
786
- $lastid = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}cjtoolbox_cjdata ORDER BY id DESC LIMIT 0,1");
787
- return $lastid;
788
- }
789
-
790
- function delete_cjdata($type, $id) {
791
- global $wpdb;
792
- if($type == '' || $id <= 0) return false;
793
- $query = $wpdb->prepare("DELETE FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '%s' AND id = '%d' LIMIT 1", $type, $id);
794
- $wpdb->query($query);
795
- return true;
796
- }
797
-
798
- function get_cjdata($type, $id) {
799
- global $wpdb;
800
-
801
- if($type == '' || $id <= 0) return false;
802
- $query = $wpdb->prepare("SELECT code FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '%s' AND id = '%d' LIMIT 1", $type, $id);
803
- $code = $wpdb->get_var($query);
804
- return $code;
805
- }
806
-
807
- function activate_plugin() {
808
- global $wpdb;
809
- $database_version = CJTOOLBOX_VERSION;
810
- $installed_db = get_option('cjtoolbox_db_version');
811
- if($database_version != $installed_db) {
812
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
813
  // Create the table structure
814
  $sql = "CREATE TABLE `{$wpdb->prefix}cjtoolbox_cjdata` (
@@ -819,7 +1029,6 @@ echo "</pre>";
819
  PRIMARY KEY ( `id` , `type` )
820
  )";
821
  dbDelta($sql);
822
- update_option( "cjtoolbox_db_version", $database_version );
823
 
824
  // Add sample code
825
  $count = $wpdb->get_var("SELECT count(*) FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type='css'");
@@ -832,81 +1041,66 @@ echo "</pre>";
832
  if($count == 0) {
833
  $wpdb->query("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('js','Inline JavaScript Declaration','<script type=\"text/javascript\">\n\n</script>')");
834
  $wpdb->query("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('js','External JavaScript','<script type=\"text/javascript\" src=\"\"></script>')");
 
835
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
836
  }
837
- }
838
- }// END Class
839
-
840
- // Let's start the plugin
841
- global $cssJSToolbox;
842
- $cssJSToolbox = new cssJSToolbox();
843
 
844
- // Activation
845
- register_activation_hook(__FILE__, array(&$cssJSToolbox, "activate_plugin"));
846
- }
847
-
848
- /** Following code copied from WordPress core */
849
- /**
850
- * Create HTML list of nav menu input items.
851
- *
852
- * @package WordPress
853
- * @since 3.0.0
854
- * @uses Walker_Nav_Menu
855
- */
856
- class cj_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
857
- function __construct( $fields = false, $boxid = 0, $type = 'page', $selected = array() ) {
858
- if ( $fields ) {
859
- $this->db_fields = $fields;
860
- }
861
- $this->boxid = $boxid;
862
- $this->selected = $selected;
863
- $this->type = $type;
864
- }
865
-
866
- function start_lvl( &$output, $depth ) {
867
- $indent = str_repeat( "\t", $depth );
868
- $output .= "\n$indent<ul class='children'>\n";
869
- }
870
-
871
- function end_lvl( &$output, $depth ) {
872
- $indent = str_repeat( "\t", $depth );
873
- $output .= "\n$indent</ul>";
874
- }
 
 
875
 
876
- /**
877
- * @see Walker::start_el()
878
- * @since 3.0.0
879
- *
880
- * @param string $output Passed by reference. Used to append additional content.
881
- * @param object $item Menu item data object.
882
- * @param int $depth Depth of menu item. Used for padding.
883
- * @param object $args
884
- */
885
- function start_el(&$output, $item, $depth, $args) {
886
-
887
- $possible_object_id = $item->object_id;
888
-
889
- $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
890
-
891
- $output .= $indent . '<li>';
892
- $output .= '<label>';
893
- $output .= '<input type="checkbox" ';
894
- if ( ! empty( $item->_add_to_top ) ) {
895
- $output .= ' add-to-top';
896
- }
897
- $output .= ' name="cjtoolbox['.$this->boxid.']['.$this->type.'][]" value="'. esc_attr( $item->object_id ) .'" ';
898
- if(is_array($this->selected)) {
899
- $output .= in_array($item->object_id, $this->selected) ? 'checked="checked"' : '';
900
- }
901
- $output .= '/> ';
902
- $output .= empty( $item->label ) ? esc_html( $item->title ) : esc_html( $item->label );
903
- $permalink = '';
904
- if($this->type == 'category') {
905
- $permalink = get_category_link($item->object_id);
906
- } else {
907
- $permalink = get_permalink($item->object_id);
908
- }
909
- $output .= '</label> <a class="l_ext" target="_blank" href="'. $permalink .'"></a>';
910
-
911
- }
912
- }
1
  <?php
2
  /*
3
  Plugin Name: CSS & JavaScript Toolbox
4
+ Plugin URI: http://wipeoutmedia.com/wordpress-plugins/css-javascript-toolbox
5
  Description: WordPress plugin to easily add custom CSS and JavaScript to individual pages
6
+ Version: 0.8
7
  Author: Wipeout Media
8
+ Author URI: http://wipeoutmedia.com/wordpress-plugins/css-javascript-toolbox
9
 
10
  Copyright (c) 2011, Wipeout Media.
11
 
25
  */
26
 
27
 
28
+ /**
29
+ * Avoid direct calls to this file where wp core files not present
30
+ */
31
  if (!function_exists ('add_action')) {
32
  header('Status: 403 Forbidden');
33
  header('HTTP/1.1 403 Forbidden');
34
  exit();
35
  }
36
 
37
+ /**
38
+ * CJT info.
39
+ */
40
+ define('CJTOOLBOX_VERSION', '0.3');
41
+ define('CJTOOLBOX_NAME', plugin_basename(dirname(__FILE__)));
42
+ define('CJTOOLBOX_TEXT_DOMAIN', CJTOOLBOX_NAME);
43
+ define('CJTOOLBOX_DEBUG', FALSE);
44
+
45
+ /**
46
+ * CJT Paths.
47
+ */
48
+ define('CJTOOLBOX_PATH', dirname(__FILE__));
49
+ define('CJTOOLBOX_INCLUDE_PATH', CJTOOLBOX_PATH . '/includes');
50
+ define('CJTOOLBOX_VIEWS_PATH', CJTOOLBOX_PATH . '/views');
51
+ define('CJTOOLBOX_VIEWS_SNIPPETS_PATH', CJTOOLBOX_PATH . '/views/snippets');
52
+
53
+ /**
54
+ * CJT URLs.
55
+ */
56
+ define('CJTOOLBOX_URL', WP_PLUGIN_URL . '/' . CJTOOLBOX_NAME );
57
+ define('CJTOOLBOX_MEDIA_URL', CJTOOLBOX_URL . '/public/media');
58
+ define('CJTOOLBOX_CSS_URL', CJTOOLBOX_URL . '/public/css');
59
+ define('CJTOOLBOX_JS_URL', CJTOOLBOX_URL . '/public/js');
60
+
61
+ /**
62
+ * Wordpress option name Prefix for modules list cache.
63
+ *
64
+ * The directory name will be added to the option name,
65
+ * so each modules directory has different cached list.
66
+ */
67
+ define('MODULES_LIST_CACHE_VAR_PREFIX', 'cjt_modules_list');
68
+
69
+ if (!class_exists('cssJSToolbox')) {
70
+ /**
71
+ * CJT class.
72
+ */
73
+ class cssJSToolbox {
74
+ /**
75
+ * WOrdpress option name.
76
+ */
77
+ const BLOCKS_OPTION_NAME = 'cjtoolbox_data';
78
+
79
+ /**
80
+ * URL to check for premium update.
81
+ */
82
+ const CHECK_UPDATE_URL = 'http://wipeoutmedia.com/wp-admin/admin-ajax.php?action=cjts_dispatcher&procedure=Updates.getLatestPremiumVersion';
83
+
84
+ /**
85
+ * Version option name.
86
+ */
87
+ const DATABASE_VERSION_OPTION_NAME = 'cjtoolbox_db_version';
88
+
89
+ /**
90
+ * Dir for uploaded images.
91
+ */
92
+ const IMAGES_UPLOAD_DIR = 'upload';
93
+
94
+ /**
95
+ * Additional scripts directory name.
96
+ */
97
+ const ADDITIONAL_SCRIPTS_DIR = 'upload';
98
+
99
+ /**
100
+ * Blocks used to output the code for
101
+ * the current request.
102
+ *
103
+ * @see cssJSToolbox::setTargetBlocks.
104
+ *
105
+ * @var array|null
106
+ */
107
+ var $blocks = null;
108
+
109
+ /**
110
+ * Security nonce used in the blocks page.
111
+ *
112
+ * @var string
113
+ */
114
+ var $security_nonce = null;
115
+
116
+ /**
117
+ * CJT options.
118
+ *
119
+ * @var array
120
+ */
121
+ var $settings = array();
122
+
123
+ /**
124
+ * CSS?JS Blocks data.
125
+ *
126
+ * @var array
127
+ */
128
+ var $cjdata = array();
129
+
130
+ /**
131
+ * Note: self::$instance is used in all HOOKS callbacks instead of $this.
132
+ * This allow other modules to override the methods of this class.
133
+ *
134
+ * Allow only single instance.
135
+ *
136
+ * @var mixed
137
+ */
138
+ public static $instance = null;
139
+
140
+ /**
141
+ * Modules engine object.
142
+ *
143
+ * @var CJTModulesEngine
144
+ */
145
+ public static $modulesEngine = null;
146
+
147
+ /**
148
+ * Premium upgrade response trasient.
149
+ *
150
+ * @var array
151
+ */
152
+ public static $premiumUpgradeTransient = null;
153
+
154
+ /**
155
+ * Initialize Plugin.
156
+ *
157
+ * @return void
158
+ */
159
+ protected function __construct() {
160
+ // Set hooks pointer.
161
+ self::$instance = $this;
162
+ // Process/Load attached modules.
163
+ if (is_admin()) {
164
+ $this->processSDModules();
165
  }
166
+ // Start this plugin once all other plugins are fully loaded.
167
+ add_action('plugins_loaded', array(&self::$instance, 'start_plugin'));
168
+ // Activation & Deactivbation.
169
+ register_activation_hook(__FILE__, array(&self::$instance, 'activate_plugin'));
170
+ register_deactivation_hook(__FILE__, array(&self::$instance, 'deactivate_plugin'));
171
+ }
172
+
173
+ /**
174
+ * Clean up single block data before saving to database.
175
+ *
176
+ * @param array Block data.
177
+ * @return array Cleaned block data.
178
+ */
179
+ protected function cleanSingleBlock($block) {
180
+ $fieldsToClean = array(
181
+ 'code',
182
+ 'links',
183
+ );
184
+ // New lines submitted to server as CRLF but displayed in browser as LF.
185
+ // PHP script and JS work on two different versions of texts.
186
+ // Replace CRLF with LF just as displayed in browsers.
187
+ foreach ($fieldsToClean as $field) {
188
+ $block[$field] = preg_replace("/\x0D\x0A/", "\x0A", $block[$field]);
189
+ }
190
+ return $block;
191
+ }
192
+
193
+ /**
194
+ * Get CJT Plugin object.
195
+ *
196
+ * @return cssJSToolbox.
197
+ */
198
+ public static function getInstance() {
199
+ if (!self::$instance) {
200
+ $instance = new cssJSToolbox();
201
  }
202
+ return self::$instance;
203
+ }
204
+
205
+ /**
206
+ * Process CJT Self delete modules only if there is modules
207
+ * available.
208
+ *
209
+ * Note: Modules can deleted them self after a while.
210
+ *
211
+ * The main concern is to avoid
212
+ * CJTModulesEngine or any other modules
213
+ * is resposible for setting cjt_process_modules value.
214
+ *
215
+ * @return void.
216
+ */
217
+ private function processSDModules() {
218
+ $modulesDirectory = 'modules';
219
+ $modulesListOptionName = MODULES_LIST_CACHE_VAR_PREFIX . "-{$modulesDirectory}";
220
+ $processModules = get_option($modulesListOptionName);
221
+ // IF processmodules is not array it means that this is the first time to run after
222
+ // the plugin installed and no list cached list, so give the modules engine the chance to collect the data.
223
+ // IF processModules is array but empty it means that modules deleted themself
224
+ // and no more modules to process.
225
+ if (!is_array($processModules) || (is_array($processModules) && (!empty($processModules)))) {
226
+ // Process/Load modules.
227
+ require_once CJTOOLBOX_INCLUDE_PATH . '/modules.inc.php';
228
+ require_once CJTOOLBOX_INCLUDE_PATH . '/modulebase.inc.php';
229
+ self::$modulesEngine = CJTModulesEngine::getInstance($modulesDirectory);
230
+ self::$modulesEngine->processAll();
231
+ }
232
+ }
233
 
234
+ /**
235
+ * Save blocks data to database.
236
+ *
237
+ * @param array Save blocks parameters if provided.
238
+ * @return void
239
+ */
240
+ function saveData($blocks = null) {
241
+ $blocks = isset($blocks) ? $blocks : $this->cjdata;
242
+ update_option(self::BLOCKS_OPTION_NAME, $blocks);
243
+ }
244
+
245
+ /**
246
+ * Read blocks data from the database.
247
+ *
248
+ * @return array Blocks data array.
249
+ */
250
+ function getData() {
251
+ $cjdata = (array) get_option(self::BLOCKS_OPTION_NAME);
252
+ $this->cjdata = apply_filters('cjt_blocks_data', $cjdata);
253
+ // This is a Database Recovery condition.
254
+ // This is not for a well-known bug. All cases has been studied.
255
+ // If under any circumstances the cjdata is empty instead of having
256
+ // a broken Plugin we just recovery by returning a block object.
257
+ // Also this will fix previous version broken Plugins.
258
+ if (empty($this->cjdata)) {
259
+ $this->cjdata[] = array(
260
+ 'block_name' => 'Default',
261
+ 'location' => 'header',
262
+ 'page' => array(),
263
+ 'category' => array(),
264
+ 'links' => '',
265
+ 'scripts' => '',
266
+ 'meta' => array(),
267
+ );
268
+ }
269
+ return $this->cjdata;
270
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
271
 
272
+ /**
273
+ * Check for premium update.
274
+ *
275
+ *
276
+ * @return void
277
+ */
278
+ public function checkPremiumUpdate() {
279
+ // Import Premium Update cron hook.
280
+ require_once 'premium-update-check.php';
281
+ CJTPremiumUpdate::check();
282
+ }
283
+
284
+ /**
285
+ * Bind Wordpress hooks.
286
+ *
287
+ * Callback for plugins_loaded.
288
+ */
289
+ function start_plugin() {
290
+ if (is_admin()) {
291
+ // New installation or check for upgrade.
292
+ // Plugin activation hook is not fired when the Plugin updated since Wordpress 3.1.
293
+ // No worries the code inside will not executed twice.
294
+ $this->checkInstallation();
295
+ // Load Plugin translation.
296
+ load_plugin_textdomain(CJTOOLBOX_TEXT_DOMAIN, null, 'css-javascript-toolbox/langs');
297
+ // Load for admin panel
298
+ add_action('admin_menu', array(&self::$instance, 'add_plugin_menu'));
299
+ // register ajax save function
300
+ add_action('wp_ajax_cjtoolbox_save', array(&self::$instance, 'ajax_save_changes'));
301
+ add_action('wp_ajax_cjtoolbox_save_newcode', array(&self::$instance, 'ajax_save_newcode'));
302
+ add_action('wp_ajax_cjtoolbox_form', array(&self::$instance, 'ajax_show_form'));
303
+ add_action('wp_ajax_cjtoolbox_get_code', array(&self::$instance, 'ajax_get_code'));
304
+ add_action('wp_ajax_cjtoolbox_delete_code', array(&self::$instance, 'ajax_delete_code'));
305
+ add_action('wp_ajax_cjtoolbox_add_block', array(&self::$instance, 'ajax_add_block'));
306
+ add_action('wp_ajax_cjtoolbox_request_template', array(&self::$instance, 'ajax_request_template'));
307
+ // Get latest update data.
308
+ self::$premiumUpgradeTransient = get_site_transient('cjt_premium_upgrade');
309
+ }
310
+ else {
311
+ // Add the script and style files to header/footer
312
+ add_action('wp_head', array(&self::$instance, 'cjtoolbox_insert_header_code'));
313
+ add_action('wp_print_scripts', array(&self::$instance, 'cjtoolbox_embedded_scripts'), 11);
314
+ add_action('wp_footer', array(&self::$instance, 'cjtoolbox_insert_footer_code'));
315
+ // Premium update check cron hook.
316
+ add_action('cjt_premium_update_checker', array(&self::$instance, 'checkPremiumUpdate'));
317
+ }
318
+ }
319
 
320
+ /**
321
+ * Output css/js codes for header.
322
+ *
323
+ * Callback for wp_head.
324
+ */
325
+ function cjtoolbox_insert_header_code() {
326
+ $this->insertcode('wp_head');
327
+ }
328
+
329
+ /**
330
+ * Output css/js codes for footer.
331
+ *
332
+ * Callback for wp_footer.
333
+ */
334
+ function cjtoolbox_insert_footer_code() {
335
+ $this->insertcode('wp_footer');
336
+ }
337
+
338
+ /**
339
+ * Enqueue embedded scripts.
340
+ * Callback for wp_enquque_scripts
341
+ */
342
+ public function cjtoolbox_embedded_scripts() {
343
+ global $wp_scripts;
344
+ if (!is_admin() && $wp_scripts) { // wp_enqueue_scripts used by backend too!!!
345
+ // Register additional script that shipped with the Plugin.
346
+ $this->registerScripts($wp_scripts);
347
+ // This is the first hook in out chan (wp_head, wp_footer, wp_enqueue_scripts).
348
+ // We'll use this hook to set target blocks.
349
+ $this->setTargetBlocks();
350
+ // We've to hooklocations wp_head and wp_footer.
351
+ foreach ($this->blocks as $hookLocation => $blocks) {
352
+ foreach ($blocks as $key => $block) {
353
+ // Get block scripts handlers.
354
+ $scriptsStrList = $this->getScriptsList($block);
355
+ $scripts = explode(',', $scriptsStrList);
356
+ if (!empty($scripts) && ($scripts[0] != '')) {
357
+ foreach ($scripts as $script) {
358
+ // If previously enqueued, dequeue and then enquque again.
359
+ // We'll use the latest block hook location.
360
+ $wp_scripts->dequeue($script);
361
+ $isFooter = ($hookLocation == 'wp_footer') ? true : false;
362
+ wp_enqueue_script($script, null, null, null, $isFooter);
363
+ } // End output scripts.
364
+ }
365
+ } // End blocks.
366
+ } // Enc hooks.
367
+ }
368
+ }
369
+
370
+ /**
371
+ * Output code for a specific location.
372
+ *
373
+ * @param string Blocks Hook/Location to output.
374
+ * @return void
375
+ */
376
+ function insertcode($hook) {
377
+ // Make sure there is at least one block for the hook.
378
+ if (isset($this->blocks[$hook])){
379
+ // Get blocks code.
380
+ foreach($this->blocks[$hook] as $blockId => $block) {
381
+ echo $block['code'] . "\n";
382
+ }
383
+ }
384
+ }
385
 
386
+ /**
387
+ * Set blocks array that should used to output the
388
+ * css/js codes for the current request.
389
+ *
390
+ * @return vod
391
+ */
392
+ protected function setTargetBlocks() {
393
+ global $post;
394
+ // Reset blocks.
395
+ $this->blocks = array();
396
+ // Home page displays a page.
397
+ $check_for = '';
398
+ if (is_front_page()) {
399
+ $check_for = 'frontpage';
400
+ }
401
+ else if (is_single() || is_home()) { // The blog page. It will be either same as front page or will be a page.
402
+ $check_for = 'allposts';
403
+ }
404
+ else if (is_page()) {
405
+ $check_for = $post->ID;
406
+ }
407
 
408
+ $this->getData();
409
+ $data = $this->cjdata;
410
+ foreach($data as $key => $block) :
411
+ // Backward compatibility.
412
+ // Catogriez blocks by hook location.
413
+ $hookLocation = $this->getHookLocation($block);
414
+ $page_list = $data[$key]['page'];
415
+ if (is_array($page_list)) {
416
+ if (is_page() && in_array('allpages', $page_list)) {
417
+ $this->blocks[$hookLocation][$key] = $block;
418
+ continue;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
  }
420
+ else if(in_array($check_for, $page_list)) {
421
+ $this->blocks[$hookLocation][$key] = $block;
422
+ continue;
423
+ }
424
+ }
425
+ if (is_category()) {
426
+ $this_category = get_query_var('cat');
427
+ $category_list = $data[$key]['category'];
428
+ if (is_array($category_list)) {
429
+ if(in_array($this_category, $category_list)) {
430
+ $this->blocks[$hookLocation][$key] = $block;
431
+ continue;
432
+ }
433
+ }
434
+ }
435
 
436
+ $pageURL = 'http';
437
+ if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
438
+ $pageURL .= "://";
439
+ if ($_SERVER["SERVER_PORT"] != "80") {
440
+ $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
441
+ } else {
442
+ $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
443
+ }
444
+ $links = $data[$key]['links'];
445
+ $link_list = explode("\n", $links);
446
+ if (in_array($pageURL, $link_list)) {
447
+ $this->blocks[$hookLocation][$key] = $block;
448
+ continue;
449
+ }
450
+ endforeach;
451
+ }
452
+
453
+ /**
454
+ * Register additional scripts shipped out with the Plugin.
455
+ *
456
+ * @param WP_SCRIPTS
457
+ * @return void
458
+ */
459
+ protected function registerScripts(&$wp_scripts) {
460
+ // Scripts shipped with Plugin.
461
+ $scripts = array(
462
+ 'jquery-cycle-all' => array(
463
+ 'file' => 'jquery.cycle.all.min.js',
464
+ 'ver' => '2.65',
465
+ 'dep' => array('jquery'),
466
+ ),
467
+ 'jquery-easing' => array(
468
+ 'file' => 'jquery.easing.js',
469
+ 'ver' => '1.3',
470
+ 'dep' => array('jquery'),
471
+ ),
472
+ );
473
+ // Register scripts.
474
+ foreach ($scripts as $handle => $script) {
475
+ $additionalJSDir = CJTOOLBOX_JS_URL . '/' . self::ADDITIONAL_SCRIPTS_DIR;
476
+ $source = "{$additionalJSDir}/{$script['file']}";
477
+ $wp_scripts->add($handle, $source, $script['dep'], $script['ver']);
478
+ }
479
+ }
480
+
481
+ /**
482
+ * Add CJT admin page.
483
+ *
484
+ * Callback for (admin_menu)
485
+ */
486
+ function add_plugin_menu() {
487
+ $this->hook_manage = add_options_page('CSS & JavaScript Toolbox' ,'CSS & JavaScript Toolbox', '10', 'cjtoolbox', array(&self::$instance, 'admin_display'));
488
+ // register callback to show styles needed for the admin page
489
+ add_action('admin_print_styles-' . $this->hook_manage, array(&self::$instance, 'admin_print_styles'));
490
+ // Load scripts for admin panel working
491
+ add_action('admin_print_scripts-' . $this->hook_manage, array(&self::$instance, 'admin_print_scripts'));
492
  }
 
 
 
 
493
 
494
+ /**
495
+ * Enqueue admin styles.
496
+ *
497
+ * Callback for admin_print_styles-[$hook_manage].
498
+ */
499
+ function admin_print_styles() {
500
+ wp_enqueue_style('thickbox');
501
+ wp_enqueue_style('cjtoolbox', CJTOOLBOX_CSS_URL . '/admin.css', '', CJTOOLBOX_VERSION, 'all');
502
+ wp_enqueue_style('jquery');
503
  }
504
 
505
+ /**
506
+ * Enqueue admin scripts.
507
+ *
508
+ * Callback for admin_print_scripts-[$hook_manage].
509
+ */
510
+ function admin_print_scripts() {
511
+ wp_enqueue_script('jquery');
512
+ wp_enqueue_script('common');
513
+ wp_enqueue_script('wp-lists');
514
+ wp_enqueue_script('postbox');
515
+ wp_enqueue_script('thickbox');
516
+ wp_enqueue_script('jquery-ui-tabs');
517
+ wp_enqueue_script('md5', CJTOOLBOX_JS_URL . '/md5-min.js'); // Md5 used to create from data hashes.
518
+ wp_enqueue_script('cjt-contenthash', CJTOOLBOX_JS_URL . '/contenthash.js');
519
+ // Admin Javascript with localization.
520
+ wp_enqueue_script('cjt-admin', CJTOOLBOX_JS_URL . '/admin.js');
521
+ $localization = array(
522
+ 'addBlockFailed' => __('Oops, unable to add CSS & JavaScript Block! Please try again!!!'),
523
+ 'UnableToReadCode' => __('Oops, unable to fetch selected {type} template! Please try again!!!'),
524
+ 'confirmDeleteTemplate' => __('Are you sure? Selected template will be deleted permanently!!!'),
525
+ 'cantDeleteTemplate' => __('Oops, unable to delete selected {type} template! Please try again!!!'),
526
+ 'templateDeleted' => __('Selected {type} template deleted successfully!'),
527
+ 'confirmDeleteBlock' => __('Are you sure you want to delete "{block_name}" block?') . "\n\n" . __('The block is not permanently deleted unless "Save Changes" button is clicked'),
528
+ 'titleFieldMissing' => __('Please enter title for code!'),
529
+ 'codeFieldMissing' => __('Please enter code to save!'),
530
+ 'noChangeMadeCouldNotSaveTemplate' => __('Code template was not saved because there were no changes made.') . "\n\n" . __('Do you wish to finish editing anyway?'),
531
+ 'couldNotSaveTemplate' => __('Could not save template, please try again.'),
532
+ 'templateSavedSuccessful' => __('"{title}" {type} code template has been saved successfully.'),
533
+ 'blockNameMissing' => __('Block name cannot be null, please type a name.'),
534
+ 'blockNameIsInUse' => __('Block name is in use. There is another block with the same name!!!') . "\n\n" . __('Please select another name.'),
535
+ );
536
+ wp_localize_script('cjt-admin', 'localization', $localization);
537
+ }
538
+
539
+ /**
540
+ * Blocks management page.
541
+ *
542
+ * Callback for menu page
543
+ */
544
+ function admin_display() {
545
+ // Import Wordpress Menu Navigation for displaying posts/pages/categories.
546
+ require CJTOOLBOX_INCLUDE_PATH . '/wpnavmenuwalker.inc.php';
547
+ // Load blocks data from database.
548
+ $this->getData();
549
+ // The idea behind making the blocks sortable is stop
550
+ // reseting the array ids.
551
+ // To avoid block id duplication we need to do not ever use the same Id again.
552
+ $existsIds = array_keys($this->cjdata);
553
+ $count = max($existsIds) + 1;
554
+ // Prepare blocks for display.
555
+ foreach ($this->cjdata as $i => $block) {
556
+ $blockName = $this->getBlockName($block, $i);
557
+ add_meta_box('cjtoolbox-' . ($i + 1), sprintf(__('CSS & JavaScript Block: %s', CJTOOLBOX_TEXT_DOMAIN), $blockName), array(&$this, 'cjtoolbox_unit'), $this->hook_manage, 'normal', 'core', $i);
558
+ }
559
+ do_action('cjt_admin_display_start', $this->cjdata);
560
+ // Output the admin management page.
561
+ require CJTOOLBOX_VIEWS_PATH . '/manage.html';
562
+ do_action('cjt_admin_display_end', $this->cjdata);
563
+ }
564
+
565
+ /**
566
+ * Get block hook location header/footer.
567
+ *
568
+ * Backward compatibility for older version that doesn't support hook location.
569
+ *
570
+ * @param array Block data.
571
+ * @param string Value to use if the hook location is not available.
572
+ * @return string Hook location name.
573
+ */
574
+ protected function getHookLocation($block, $default = 'wp_head') {
575
+ return isset($block['location']) ? $block['location'] : $default;
576
+ }
577
+
578
+ /**
579
+ * Get block scripts list.
580
+ *
581
+ * Backward compatibility for older version that doesn't support embedded scripting.
582
+ *
583
+ * @param array Block data.
584
+ * @return string
585
+ */
586
+ protected function getScriptsList($block, $default = '') {
587
+ // For old version that doesn't support embedded scripts.
588
+ $scripts = isset($block['scripts']) ? $block['scripts'] : $default;
589
+ return $scripts;
590
+ }
591
+
592
+ /**
593
+ * Get block name.
594
+ *
595
+ * Backward compatibility for older version that doesn't support block names.
596
+ *
597
+ * @param array Block data.
598
+ * @param integer Block id.
599
+ * @return string Block name.
600
+ */
601
+ protected function getBlockName($block, $blockId, $oldVersionPrefix = '') {
602
+ $oldNameStyle = ($blockId + 1);
603
+ if (isset($block['block_name'])) {
604
+ $blockName = $block['block_name'];
605
+ }
606
+ else {
607
+ $blockName = "{$oldVersionPrefix}{$oldNameStyle}";
608
+ }
609
+ return $blockName;
610
+ }
611
+
612
+ /**
613
+ * Represent single block markup constructor.
614
+ *
615
+ * @param null Not used.
616
+ * @param integer Block Id.
617
+ * @param boolean Indicate whether the request is Ajax request.
618
+ * @return void
619
+ */
620
+ function cjtoolbox_unit($data = '', $arg = '', $ajax = false) {
621
+ $boxid = -1; // Because block 1 might have some content...
622
+ if ($arg != '') {
623
+ $boxid = $arg['args'];
624
+ }
625
+ // E_ALL complain.
626
+ // We don't want to use $this->cjdata[$boxid] when the $this->cjdata[$boxid] is not set.
627
+ // Because the previous version do that (views/snippets/block.tmpl) we need to cover.
628
+ if ($ajax) {
629
+ // This won't saved to the database.
630
+ $this->cjdata[$boxid] = array(
631
+ 'block_name' => ($boxid + 1),
632
+ 'location' => 'header',
633
+ 'code' => '',
634
+ 'page' => array(),
635
+ 'category' => array(),
636
+ 'links' => '',
637
+ 'scripts' => '',
638
+ 'meta' => array(),
639
+ );
640
+ }
641
+ $currentBlock = $this->cjdata[$boxid];
642
+ $blocksCount = count($this->cjdata);
643
+ $blockName = $this->getBlockName($currentBlock, $boxid);
644
+ require CJTOOLBOX_VIEWS_SNIPPETS_PATH . '/block.tmpl';
645
+ }
646
 
647
+ /**
648
+ * Get taxanomy terms checkboxes selection list.
649
+ *
650
+ * @param string List Id.
651
+ * @param array Selected terms list.
652
+ */
653
+ function show_taxonomy_with_checkbox($boxid, $taxonomy_selected) {
654
+ $taxonomy_name = 'category';
655
+ $args = array(
656
+ 'child_of' => 0,
657
+ 'exclude' => '',
658
+ 'hide_empty' => false,
659
+ 'hierarchical' => 1,
660
+ 'include' => '',
661
+ 'include_last_update_time' => false,
662
+ 'number' => 9999,
663
+ 'order' => 'ASC',
664
+ 'orderby' => 'name',
665
+ 'pad_counts' => false,
666
+ );
667
+ $terms = get_terms($taxonomy_name, $args);
668
+ if (!$terms || is_wp_error($terms)) {
669
+ // No items
670
+ return;
671
+ }
672
+ $db_fields = false;
673
+ if (is_taxonomy_hierarchical($taxonomy_name)) {
674
+ $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' );
675
+ }
676
+ $walker = new cj_Walker_Nav_Menu_Checklist($db_fields, $boxid, 'category', $taxonomy_selected);
677
+ $args['walker'] = $walker;
678
+ echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $terms), 0, (object) $args);
679
+ }
680
+
681
+ /**
682
+ * Get pages terms checkboxes selection list.
683
+ *
684
+ * @param string List Id.
685
+ * @param array Selected pages list.
686
+ */
687
+ function show_pages_with_checkbox($boxid, $pages_selected) {
688
+ $post_type_name = 'page';
689
+ $args = array(
690
+ 'order' => 'ASC',
691
+ 'orderby' => 'title',
692
+ 'posts_per_page' => 9999,
693
+ 'post_type' => $post_type_name,
694
+ 'suppress_filters' => true,
695
+ 'update_post_term_cache' => false,
696
+ 'update_post_meta_cache' => false
697
+ );
698
+ // @todo transient caching of these results with proper invalidation on updating of a post of this type
699
+ $get_posts = new WP_Query;
700
+ $posts = $get_posts->query($args);
701
+ if (!$get_posts->post_count) {
702
+ // No items
703
+ return;
704
+ }
705
+ $db_fields = false;
706
+ if (is_post_type_hierarchical($post_type_name)) {
707
+ $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
708
+ }
709
+ $walker = new cj_Walker_Nav_Menu_Checklist($db_fields, $boxid, 'page', $pages_selected);
710
+ $post_type_object = get_post_type_object($post_type_name);
711
+ $args['walker'] = $walker;
712
+ $checkbox_items = walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args);
713
+ echo $checkbox_items;
714
+ }
715
+
716
+ /**
717
+ * Get add new block dialog.
718
+ *
719
+ * @return void
720
+ */
721
+ function ajax_add_block() {
722
+ check_ajax_referer('cjtoolbox-admin', 'security');
723
+ // We need the security nonce for the new block.
724
+ $this->security_nonce = $_REQUEST['security'];
725
+ // Import Wordpress Menu Navigation for displaying posts/pages/categories.
726
+ require CJTOOLBOX_INCLUDE_PATH . '/wpnavmenuwalker.inc.php';
727
+
728
+ $args = array();
729
+ // Load blocks from database.
730
+ $this->getData();
731
+ $count = (int) $_POST['count'];
732
+ $args['args'] = $count;
733
+ require CJTOOLBOX_VIEWS_SNIPPETS_PATH . '/newblock.html.tmpl';
734
+ die();
735
+ }
736
+
737
+ /**
738
+ * Request forms templates(e.g edit block name popup, etc..)
739
+ *
740
+ * @param string Views path. Useful for modules to utilize from the method.
741
+ * @param array Params to make visible to the template file.
742
+ * @return void
743
+ */
744
+ function ajax_request_template($viewsPath = CJTOOLBOX_VIEWS_SNIPPETS_PATH, $param = array()) {
745
+ check_ajax_referer('cjtoolbox-admin', 'security');
746
+ $name = $_GET['name'];
747
+ if (preg_match('/[a-z\_\-]+/', $name)) {
748
+ // Make parameters visible to the template.
749
+ extract($param);
750
+ // Include the file.
751
+ $templateName = "{$name}.html.tmpl";
752
+ $pathToTemplate = "{$viewsPath}/{$templateName}";
753
+ require $pathToTemplate;
754
+ }
755
+ die();
756
+ }
757
+
758
+ /**
759
+ * Save new code template to database.
760
+ *
761
+ * @return void
762
+ */
763
+ function ajax_save_newcode() {
764
+ check_ajax_referer('cjtoolbox-popup', 'security');
765
+ // Add new row to cjdata table
766
+ $type = $_POST['type'];
767
+ $title = $_POST['title'];
768
+ // Get RAW data indpendent from magic_quote_gpc, let Wordpress $wpdb->update/insert do the rest.
769
+ $code = filter_input(INPUT_POST, 'code', FILTER_UNSAFE_RAW);
770
+ $id = filter_input(INPUT_POST, 'id', FILTER_VALIDATE_INT);
771
+ $response = $this->add_cjdata($id, $type, $title, $code);
772
+ die($response);
773
  }
774
 
775
+ /**
776
+ * Save blocks data.
777
+ *
778
+ * @return void
779
+ */
780
+ function ajax_save_changes() {
781
+ check_ajax_referer('cjtoolbox-admin', 'security');
782
+ $response = array();
783
+ if($_POST['action'] == 'cjtoolbox_save') {
784
+ // Save data and return 1 on success.
785
+ // Get RAW data indpendent from magic_quote_gpc, let Wordpress $wpdb->update/insert do the escaping.
786
+ $blocks = filter_input(INPUT_POST, 'cjtoolbox', FILTER_UNSAFE_RAW, FILTER_REQUIRE_ARRAY);
787
+ $blocks = apply_filters('cjt_save_data', $blocks);
788
+ // Take a copy from the first block.
789
+ $firstBlock = each($blocks);
790
+ foreach($blocks as $id => $block) {
791
+ if ($block['code'] == '') {
792
+ // Don't store blocks with empty code.
793
+ unset($blocks[$id]);
794
+ }
795
+ else {
796
+ // Clean up block data.
797
+ // Prepare for storing.
798
+ $blocks[$id] = $this->cleanSingleBlock($block);
799
+ }
800
+ }
801
+ // Because we may get all the blocks with empty code and
802
+ // we need to maintain at least one block.
803
+ // If all blocks is empty take the first one.
804
+ if (empty($blocks)) {
805
+ $blocks[$firstBlock['key']] = $firstBlock['value'];
806
+ }
807
+ $this->cjdata = $blocks;
808
+ $this->saveData();
809
+ do_action('cjt_data_saved', $blocks);
810
+ $response['savedIds'] = array_keys($blocks);
811
+ $response['availableCount'] = count($blocks);
812
+ }
813
+ die(json_encode($response)); // Our Response.
814
+ }
815
 
816
+ /**
817
+ * Delete selected code template.
818
+ *
819
+ * @return void
820
+ */
821
+ function ajax_delete_code() {
822
+ check_ajax_referer('cjtoolbox-admin', 'security');
823
+ $type = $_POST['type'];
824
+ $id = (int) $_POST['id'];
825
+ if ($id <=0 || ($type != 'js' && $type != 'css')) {
826
+ return __('Invalid Request: Unable to process the request!', CJTOOLBOX_TEXT_DOMAIN);
827
+ }
828
+ $this->delete_cjdata($type, $id);
829
+ die('1');
830
+ }
831
 
832
+ /**
833
+ * Get code for a specific template.
834
+ *
835
+ * @return void
836
+ */
837
+ function ajax_get_code() {
838
+ check_ajax_referer('cjtoolbox-admin', 'security');
839
+ $type = $_POST['type'];
840
+ $id = (int) $_POST['id'];
841
+ if($id <=0 || ($type != 'js' && $type != 'css')) {
842
+ return __('Invalid Request: Unable to process the request!', CJTOOLBOX_TEXT_DOMAIN);
843
+ }
844
+ $code = $this->get_cjdata($type, $id);
845
+ die($code);
846
+ }
847
 
848
+ /**
849
+ * New code popup constructor.
850
+ *
851
+ * @return void
852
+ */
853
+ function ajax_show_form() {
854
+ global $wpdb;
855
+ check_ajax_referer('cjtoolbox-admin', 'security');
856
+ $type = '';
857
+ switch($_GET['type']) {
858
+ case 'js':
859
+ $type = 'js';
860
+ break;
861
+ case 'css':
862
+ default:
863
+ $type = 'css';
864
+ break;
865
+ }
866
+ $editId = (int) $_GET['id'];
867
+ if ($editId) {
868
+ $query = "SELECT *
869
+ FROM {$wpdb->prefix}cjtoolbox_cjdata
870
+ WHERE id = %d";
871
+ $query = $wpdb->prepare($query, $editId);
872
+ $template = $wpdb->get_row($query, ARRAY_A);
873
+ }
874
+ else {
875
+ // Dummy object for filling the form.
876
+ $template = array(
877
+ 'type' => $type,
878
+ 'title' => '',
879
+ 'code' => '',
880
+ );
881
+ }
882
+ require CJTOOLBOX_VIEWS_SNIPPETS_PATH . "/newcode.html.tmpl";
883
+ die();
884
+ }
885
 
886
+ /**
887
+ * Get code template selection list.
888
+ *
889
+ * @param string Type of template. It could be 'css' or 'js';
890
+ * @param string Unique identified for the block list.
891
+ * @return void
892
+ */
893
+ function show_dropdown_box($type, $boxid) {
894
+ global $wpdb;
895
+ $query = $wpdb->prepare("SELECT id, title FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '{$type}'");
896
+ $list = $wpdb->get_results($query);
897
+ if(count($list)) {
898
+ echo '<select id="cjtoolbox-'.$type.'-'.$boxid.'" class="cjtoolbox-'.$type.'">';
899
+ foreach($list as $def) {
900
+ echo '<option value="' . $def->id . '">'. $def->title . '</option>';
901
+ }
902
+ echo '</select>';
903
+ }
904
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
905
 
906
+ /**
907
+ * Add a new code template to database.
908
+ *
909
+ * @param string Template type.
910
+ * @param string Template title.
911
+ * @param string Template content.
912
+ * @return integer|null Template id when success or null if faild.
913
+ */
914
+ function add_cjdata($id, $type, $title, $code) {
915
+ global $wpdb;
916
+ $result = array('operation' => '', 'id' => '', 'code' => '');
917
+ // Validate.
918
+ if($type == '' || $title == '' || $code == '') {
919
+ return false;
920
+ }
921
+ // Update exists record.
922
+ if ($id) {
923
+ $data = array(
924
+ 'title' => $title,
925
+ 'code' => $code,
926
+ );
927
+ $filter = array(
928
+ 'id' => $id,
929
+ 'type' => $type,
930
+ );
931
+ $result['id'] = $id;
932
+ $result['operation'] = 'update';
933
+ $result['responseCode'] = $wpdb->update("{$wpdb->prefix}cjtoolbox_cjdata", $data, $filter);
934
+ }
935
+ else {
936
+ $query = $wpdb->prepare("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('%s', '%s', '%s')", $type, $title, $code);
937
+ $wpdb->query($query);
938
+ // Get inserted id
939
+ $result['id'] = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}cjtoolbox_cjdata ORDER BY id DESC LIMIT 0,1");
940
+ $result['operation'] = 'insert';
941
+ $result['responseCode'] = $result['id'];
942
+ }
943
+ return json_encode($result);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
944
  }
 
 
945
 
946
+ /**
947
+ * Delete template.
948
+ *
949
+ * @param string Template type css/js.
950
+ * @param integer Id of the template.
951
+ * @return true.
952
+ */
953
+ function delete_cjdata($type, $id) {
954
+ global $wpdb;
955
+ if($type == '' || $id <= 0) return false;
956
+ $query = $wpdb->prepare("DELETE FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '%s' AND id = '%d' LIMIT 1", $type, $id);
957
+ $wpdb->query($query);
958
+ return true;
959
+ }
960
 
961
+ /**
962
+ * Get code for a specific template.
963
+ *
964
+ * @param string Template type.
965
+ * @param integer Template Id.
966
+ * @return string|null
967
+ */
968
+ function get_cjdata($type, $id) {
969
+ global $wpdb;
970
+ if($type == '' || $id <= 0) return false;
971
+ $query = $wpdb->prepare("SELECT code FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '%s' AND id = '%d' LIMIT 1", $type, $id);
972
+ $code = $wpdb->get_var($query);
973
+ return $code;
974
+ }
975
 
976
+ /**
977
+ * Install/Upgrade CJT Plugin.
978
+ *
979
+ * return void.
980
+ */
981
+ function checkInstallation() {
982
+ $installed_db = get_option(self::DATABASE_VERSION_OPTION_NAME);
983
+ if (!$installed_db) { // New installation.
984
+ do_action('cjt_install');
985
+ $this->install();
986
+ add_option(self::DATABASE_VERSION_OPTION_NAME, CJTOOLBOX_VERSION);
987
+ do_action('cjt_installed');
988
+ }
989
+ else if(version_compare(CJTOOLBOX_VERSION, $installed_db) == 1) { // Upgrade version 0.2.
990
+ do_action('cjt_upgrade', $installed_db);
991
+ $this->upgrade();
992
+ update_option(self::DATABASE_VERSION_OPTION_NAME, CJTOOLBOX_VERSION);
993
+ do_action('cjt_upgraded', $installed_db);
994
  }
995
+ }
996
+
997
+ /**
998
+ * Activate the Plugin
999
+ *
1000
+ * Callback for register_Activation_hook.
1001
+ */
1002
+ public function activate_plugin() {
1003
+ // Schedule Premium Check Update event.
1004
+ wp_schedule_event(time() + 60, "daily", 'cjt_premium_update_checker');
1005
+ }
1006
+
1007
+ /**
1008
+ * Call back for register_deactivation_hook.
1009
+ */
1010
+ public function deactivate_plugin() {
1011
+ // Clear previously scheduled event (@see activate_plugin).
1012
+ wp_clear_scheduled_hook('cjt_premium_update_checker');
1013
+ }
1014
+
1015
+ /**
1016
+ * Install the Plugin.
1017
+ *
1018
+ * @return void
1019
+ */
1020
+ public function install() {
1021
+ global $wpdb;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1022
  require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
1023
  // Create the table structure
1024
  $sql = "CREATE TABLE `{$wpdb->prefix}cjtoolbox_cjdata` (
1029
  PRIMARY KEY ( `id` , `type` )
1030
  )";
1031
  dbDelta($sql);
 
1032
 
1033
  // Add sample code
1034
  $count = $wpdb->get_var("SELECT count(*) FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type='css'");
1041
  if($count == 0) {
1042
  $wpdb->query("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('js','Inline JavaScript Declaration','<script type=\"text/javascript\">\n\n</script>')");
1043
  $wpdb->query("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('js','External JavaScript','<script type=\"text/javascript\" src=\"\"></script>')");
1044
+ $wpdb->query("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('js','jQuery Code Wrapper','<script type=\"text/javascript\">\n(function(\$) {\n\n\t//PUT YOUR CODE HERE...\n\n})(jQuery);\n</script>')");
1045
  }
1046
+ // Add default block.
1047
+ $sampleCode = '<!-- ' . __('CSS & JAVASCRIPT TOOLBOX - INSTRUCTIONS AND DEMO') . " -->\n";
1048
+ $sampleCode .= '<!-- ' . __('Feel free to delete all of this text at any time. For more information, please click \'Hints & Tips\'') . " -->\n\n";
1049
+ $sampleCode .= '<!-- ' . __('Write your CSS and JS code here, then apply it by using one of the tabs (Pages, Categories, URL) from the panel on the right') . " -->\n";
1050
+ $sampleCode .= '<!-- ' . __('The example JavaScript code shown below will display an alert message box') . " -->\n";
1051
+ $sampleCode .= '<!-- ' . __('To see this code in action, lets click the "Front Page" checkbox from the panel on the right') . " -->\n";
1052
+ $sampleCode .= '<!-- ' . __('Click the blue \'Save All Changes\' button, then click the Front Page navigation icon to open the page in a new window') . " -->\n";
1053
+ $sampleCode .= '<!-- ' . __('Have fun!!!') . " -->\n\n";
1054
+ $sampleCode .= "<script type='text/javascript'>\n\talert(\"Thank you for installing CSS & JavaScript Toolbox.\\nIf you find this plugin useful, please let us know at www.WipeoutMedia.com\");\n</script>\n";
1055
+
1056
+ $defaultBlock = array(
1057
+ 'block_name' => 'Default',
1058
+ 'location' => 'header',
1059
+ 'code' => $sampleCode,
1060
+ 'page' => array(),
1061
+ 'category' => array(),
1062
+ 'links' => '',
1063
+ 'scripts' => '',
1064
+ 'meta' => array(),
1065
+ );
1066
+ $this->cjdata = array($defaultBlock);
1067
+ $this->saveData();
1068
  }
 
 
 
 
 
 
1069
 
1070
+ /**
1071
+ * Upgrade the plugin from the last version.
1072
+ *
1073
+ * @return void
1074
+ */
1075
+ public function upgrade() {
1076
+ // Add meta array for all blocks.
1077
+ $blocks = (array) get_option(self::BLOCKS_OPTION_NAME);
1078
+ foreach ($blocks as $id => $block) {
1079
+ // Add meta field to the exists blocks.
1080
+ // This method should called one time but for any reason
1081
+ // don't overriding exists values.
1082
+ if (!array_key_exists('meta', $block)) {
1083
+ $blocks[$id]['meta'] = array();
1084
+ }
1085
+ $blocks[$id] = $this->cleanSingleBlock($block);
1086
+ }
1087
+ // Save blocks.
1088
+ update_option(cssJSToolbox::BLOCKS_OPTION_NAME, $blocks);
1089
+ }
1090
+
1091
+ /**
1092
+ * Print CSSJtoolbox Debug message.
1093
+ *
1094
+ * @param mixed $message
1095
+ */
1096
+ public static function printDebugMessage($message) {
1097
+ if (CJTOOLBOX_DEBUG) {
1098
+ echo "{$message}<br />";
1099
+ }
1100
+ }
1101
+
1102
+ }// END Class
1103
 
1104
+ // Let's start the plugin
1105
+ cssJSToolbox::getInstance();
1106
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
includes/modulebase.inc.php ADDED
@@ -0,0 +1,173 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ */
5
+
6
+ /**
7
+ *
8
+ */
9
+ abstract class CJTModuleBase {
10
+
11
+ /**
12
+ * instance to cjToolbox object.
13
+ *
14
+ * @var cssJSToolbox
15
+ */
16
+ protected $cjToolbox = null;
17
+
18
+ /**
19
+ * Is this module is to extend the cssJSToolbox
20
+ * object method.
21
+ *
22
+ * @var boolean
23
+ */
24
+ protected $extendCJToolbox = true;
25
+
26
+ /**
27
+ * Module info struct passed by modules::processAll method.
28
+ *
29
+ * @var array
30
+ */
31
+ protected $moduleInfo = null;
32
+
33
+ /**
34
+ * If the method is not implemented in $this
35
+ * object delegate cssJSToolbox method.
36
+ *
37
+ * @param string Method name.
38
+ * @param array Parameters.
39
+ * @return mixed.
40
+ */
41
+ public function __call($method, $parameters) {
42
+ if ($this->extendCJToolbox) {
43
+ return call_user_func_array(array($this->cjToolbox, $method), $parameters);
44
+ }
45
+ else {
46
+ trigger_error("Module method '{$method}' is not found", E_USER_ERROR);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Module base constructor.
52
+ *
53
+ * This method should be called manually from the derivded classed
54
+ *
55
+ * @param array Module info.
56
+ * @param boolean Is to extended cssJSToolbox object methods.
57
+ * @return void
58
+ */
59
+ protected function __construct($moduleInfo, $extendCJToolbox = false) {
60
+ $this->moduleInfo = $moduleInfo;
61
+ $this->extendCJToolbox = $extendCJToolbox;
62
+ if ($extendCJToolbox) {
63
+ // Extended cssJSToolbox class functionaity.
64
+ $this->cjToolbox = cssJSToolbox::$instance;
65
+ cssJSToolbox::$instance = $this;
66
+ }
67
+ }
68
+
69
+ /**
70
+ * If the property is not implemented in $this
71
+ * object delegate cssJSToolbox property.
72
+ *
73
+ * @param string Property name.
74
+ * @return mixed
75
+ */
76
+ public function __get($property) {
77
+ if ($this->extendCJToolbox) {
78
+ return $this->cjToolbox->$property;
79
+ }
80
+ else {
81
+ trigger_error("Module property '{$property}' is not found", E_USER_ERROR);
82
+ }
83
+ }
84
+
85
+ /**
86
+ * If the property is not implemented in $this
87
+ * object delegate cssJSToolbox property.
88
+ *
89
+ * @param string Property name.
90
+ * @param array Parameters.
91
+ * @return void
92
+ */
93
+ public function __set($property, $value) {
94
+ if ($this->extendCJToolbox) {
95
+ $this->cjToolbox->$property = $value;
96
+ }
97
+ else {
98
+ trigger_error("Module property '{$property}' is not found", E_USER_ERROR);
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Get CSS file URL for the module.
104
+ *
105
+ * @param string CSS file.
106
+ * @return string CSS file URL
107
+ */
108
+ protected function getCSSFileURL($file) {
109
+ return $this->getURL("public/css/{$file}");
110
+ }
111
+
112
+ /**
113
+ * Get Javascript file URL for the module.
114
+ *
115
+ * @param string Javascript file.
116
+ * @return string JS file URL
117
+ */
118
+ protected function getJSFileURL($file) {
119
+ return $this->getURL("public/js/{$file}");
120
+ }
121
+
122
+ /**
123
+ * Get path to module file.
124
+ *
125
+ * @param string
126
+ * @return string File path.
127
+ */
128
+ protected function getPath($file = '') {
129
+ $file = $file ? "/{$file}" : '';
130
+ $path = "{$this->moduleInfo['path']}{$file}";
131
+ return $path;
132
+ }
133
+
134
+ /**
135
+ * Get module file URL.
136
+ *
137
+ * @param
138
+ * @param string File to get the URL to or module
139
+ * URL if omitted.
140
+ * @return string File URL.
141
+ */
142
+ protected function getURL($file = '') {
143
+ $file = $file ? "/{$file}" : '';
144
+ $url = "{$this->moduleInfo['url']}{$file}";
145
+ return $url;
146
+ }
147
+
148
+ /**
149
+ * put your comment there...
150
+ *
151
+ * @param mixed $view
152
+ * @param mixed $parameters
153
+ */
154
+ public function getView($view, $parameters) {
155
+ $viewPath = $this->getPath("views/{$view}.html.tmpl");
156
+ // Make parameters visible to the view.
157
+ extract($parameters);
158
+ // Get the content.
159
+ ob_start();
160
+ require $viewPath;
161
+ $content = ob_get_clean();
162
+ return $content;
163
+ }
164
+
165
+ /**
166
+ * put your comment there...
167
+ *
168
+ */
169
+ public function leaveCJToolboxObject() {
170
+ cssJSToolbox::$instance = $this->cjToolbox;
171
+ }
172
+
173
+ } // End class.
includes/modules.inc.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @version $Id ; modules.inc.php 16:08:23 07:02:2012 Ahmed Said ;
4
+ */
5
+
6
+ /**
7
+ * Cover all modules functionality.
8
+ *
9
+ * @author Ahmed Said.
10
+ */
11
+ class CJTModulesEngine {
12
+ /**
13
+ * Modules directory.
14
+ *
15
+ * @var string
16
+ */
17
+ private $directory = '';
18
+
19
+ /**
20
+ * All created/processed modules instances.
21
+ *
22
+ * @var array
23
+ */
24
+ public $modules = array();
25
+
26
+ /**
27
+ * To process modules list.
28
+ *
29
+ * @var array
30
+ */
31
+ private $modulesList = array();
32
+
33
+ /**
34
+ * Wordpress option name for the modules list
35
+ * for the modules directory.
36
+ *
37
+ * @var string
38
+ */
39
+ private $modulesListOptionName = '';
40
+
41
+ /**
42
+ * Create new CJTModulesEngine object.
43
+ *
44
+ * @param string Directory to search for modules.
45
+ * @return void
46
+ */
47
+ public function __construct($modulesDirectory = 'modules') {
48
+ $this->directory = $modulesDirectory;
49
+ $this->modulesListOptionName = MODULES_LIST_CACHE_VAR_PREFIX . "-{$this->directory}";;
50
+ $this->readModulesList();
51
+ }
52
+
53
+ /**
54
+ * Delete module by ID.
55
+ *
56
+ * The deleted module won't never run again
57
+ * until added again by the add method.
58
+ *
59
+ * The module will stay running after deleted however
60
+ * it won't running the next time.
61
+ *
62
+ * @return boolean
63
+ */
64
+ public function delete($moduleId) {
65
+ if ($moduleId && is_scalar($moduleId)) {
66
+ if (array_key_exists($moduleId, $this->modulesList)) {
67
+ unset($this->modulesList[$moduleId]);
68
+ update_option($this->modulesListOptionName, $this->modulesList);
69
+ }
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Create new CJTModulesEngine object.
75
+ * @see __construct for parameters list.
76
+ * @return CJTModulesEngine
77
+ */
78
+ public static function getInstance($modulesDirectory = 'modules') {
79
+ $instance = new CJTModulesEngine($modulesDirectory);
80
+ return $instance;
81
+ }
82
+
83
+ /**
84
+ * Process all available modules.
85
+ *
86
+ * @return void
87
+ */
88
+ public function processAll() {
89
+ // We're that this variable will hold array @see readModulesList called from __construct.
90
+ foreach ($this->modulesList as $moduleId => $module) {
91
+ if (file_exists($module['file'])) {
92
+ // If this method called twice don't desttoy the module
93
+ // object.
94
+ $currentModuleObject = isset($this->modules[$moduleId]) ? $this->modules[$moduleId] : null;
95
+ $mayBeObject = require_once $module['file'];
96
+ $this->modules[$moduleId] = !is_bool($mayBeObject) ? $mayBeObject : $currentModuleObject;
97
+ cssJSToolbox::printDebugMessage("Processing Module: {$moduleId}");
98
+ }
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Read modules list from cache or collect
104
+ * from modules directory is not caches yet.
105
+ *
106
+ * @return void
107
+ */
108
+ public function readModulesList() {
109
+ $cachedModulesList = get_option($this->modulesListOptionName);
110
+ // Cache modules list only if not cached before.
111
+ // Empty array is another case and it mean
112
+ // that this method is never called before.
113
+ if (!is_array($cachedModulesList)) {
114
+ cssJSToolbox::printDebugMessage("Caching Modules List");
115
+ $cachedModulesList = array();
116
+ $modulesDirPath = CJTOOLBOX_PATH . "/{$this->directory}";
117
+ $modulesIterator = opendir($modulesDirPath);
118
+ // Get all modules.
119
+ while ($moduleDir = readdir($modulesIterator)) {
120
+ // Build module main file path.
121
+ $moduleFileName = "{$moduleDir}.php";
122
+ $modulePath = "{$modulesDirPath}/{$moduleDir}";
123
+ if ($moduleDir != '.' && $moduleDir != '..' & is_dir($modulePath)) {
124
+ $moduleFilePath = "{$modulePath}/{$moduleFileName}";
125
+ $module = array(
126
+ 'id' => $moduleDir,
127
+ 'path' => $modulePath,
128
+ 'url' => CJTOOLBOX_URL . "/modules/{$moduleDir}",
129
+ 'file' => $moduleFilePath,
130
+ 'status' => 'active',
131
+ );
132
+ $cachedModulesList[$moduleDir] = $module;
133
+ }
134
+ }
135
+ closedir($modulesIterator);
136
+ // Update database modules list.
137
+ update_option($this->modulesListOptionName, $cachedModulesList);
138
+ }
139
+ $this->modulesList = $cachedModulesList;
140
+ }
141
+
142
+ } // End class.
includes/wpnavmenuwalker.inc.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /** Following code copied from WordPress core */
3
+ /**
4
+ * Create HTML list of nav menu input items.
5
+ *
6
+ * @package WordPress
7
+ * @since 3.0.0
8
+ * @uses Walker_Nav_Menu
9
+ */
10
+ class cj_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
11
+ function __construct( $fields = false, $boxid = 0, $type = 'page', $selected = array() ) {
12
+ if ( $fields ) {
13
+ $this->db_fields = $fields;
14
+ }
15
+ $this->boxid = $boxid;
16
+ $this->selected = $selected;
17
+ $this->type = $type;
18
+ }
19
+
20
+ function start_lvl( &$output, $depth ) {
21
+ $indent = str_repeat( "\t", $depth );
22
+ $output .= "\n$indent<ul class='children'>\n";
23
+ }
24
+
25
+ function end_lvl( &$output, $depth ) {
26
+ $indent = str_repeat( "\t", $depth );
27
+ $output .= "\n$indent</ul>";
28
+ }
29
+
30
+ /**
31
+ * @see Walker::start_el()
32
+ * @since 3.0.0
33
+ *
34
+ * @param string $output Passed by reference. Used to append additional content.
35
+ * @param object $item Menu item data object.
36
+ * @param int $depth Depth of menu item. Used for padding.
37
+ * @param object $args
38
+ */
39
+ function start_el(&$output, $item, $depth, $args) {
40
+ $possible_object_id = $item->object_id;
41
+ $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
42
+ $output .= $indent . '<li>';
43
+ $output .= '<label>';
44
+ $output .= '<input type="checkbox" ';
45
+ if ( ! empty( $item->_add_to_top ) ) {
46
+ $output .= ' add-to-top';
47
+ }
48
+ $output .= ' name="cjtoolbox['.$this->boxid.']['.$this->type.'][]" value="'. esc_attr( $item->object_id ) .'" ';
49
+ if(is_array($this->selected)) {
50
+ $output .= in_array($item->object_id, $this->selected) ? 'checked="checked"' : '';
51
+ }
52
+ $output .= '/> ';
53
+ $output .= empty( $item->label ) ? esc_html( $item->title ) : esc_html( $item->label );
54
+ $permalink = '';
55
+ if($this->type == 'category') {
56
+ $permalink = get_category_link($item->object_id);
57
+ } else {
58
+ $permalink = get_permalink($item->object_id);
59
+ }
60
+ $output .= '</label> <a class="l_ext" target="_blank" href="'. $permalink .'"></a>';
61
+
62
+ }
63
+ }
64
+ ?>
langs/css-javascript-toolbox.pot ADDED
@@ -0,0 +1,533 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: PACKAGE VERSION\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2012-02-28 07:22-0500\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "MIME-Version: 1.0\n"
16
+ "Content-Type: text/plain; charset=CHARSET\n"
17
+ "Content-Transfer-Encoding: 8bit\n"
18
+
19
+ #: css-js-toolbox.php:516
20
+ msgid "Oops, unable to add CSS & JavaScript Block! Please try again!!!"
21
+ msgstr ""
22
+
23
+ #: css-js-toolbox.php:517
24
+ msgid "Oops, unable to fetch selected {type} template! Please try again!!!"
25
+ msgstr ""
26
+
27
+ #: css-js-toolbox.php:518
28
+ msgid "Are you sure? Selected template will be deleted permanently!!!"
29
+ msgstr ""
30
+
31
+ #: css-js-toolbox.php:519
32
+ msgid "Oops, unable to delete selected {type} template! Please try again!!!"
33
+ msgstr ""
34
+
35
+ #: css-js-toolbox.php:520
36
+ msgid "Selected {type} template deleted successfully!"
37
+ msgstr ""
38
+
39
+ #: css-js-toolbox.php:521
40
+ msgid "Are you sure you want to delete \"{block_name}\" block?"
41
+ msgstr ""
42
+
43
+ #: css-js-toolbox.php:521
44
+ msgid ""
45
+ "The block is not permanently deleted unless \"Save Changes\" button is "
46
+ "clicked"
47
+ msgstr ""
48
+
49
+ #: css-js-toolbox.php:522
50
+ msgid "Please enter title for code!"
51
+ msgstr ""
52
+
53
+ #: css-js-toolbox.php:523
54
+ msgid "Please enter code to save!"
55
+ msgstr ""
56
+
57
+ #: css-js-toolbox.php:524
58
+ msgid "Code template was not saved because there were no changes made."
59
+ msgstr ""
60
+
61
+ #: css-js-toolbox.php:524
62
+ msgid "Do you wish to finish editing anyway?"
63
+ msgstr ""
64
+
65
+ #: css-js-toolbox.php:525
66
+ msgid "Could not save template, please try again."
67
+ msgstr ""
68
+
69
+ #: css-js-toolbox.php:526
70
+ msgid "\"{title}\" {type} code template has been saved successfully."
71
+ msgstr ""
72
+
73
+ #: css-js-toolbox.php:527
74
+ msgid "Block name cannot be null, please type a name."
75
+ msgstr ""
76
+
77
+ #: css-js-toolbox.php:528
78
+ msgid "Block name is in use. There is another block with the same name!!!"
79
+ msgstr ""
80
+
81
+ #: css-js-toolbox.php:528
82
+ msgid "Please select another name."
83
+ msgstr ""
84
+
85
+ #: css-js-toolbox.php:551 views/snippets/newblock.html.tmpl:2
86
+ #, php-format
87
+ msgid "CSS & JavaScript Block: %s"
88
+ msgstr ""
89
+
90
+ #: css-js-toolbox.php:820 css-js-toolbox.php:836
91
+ msgid "Invalid Request: Unable to process the request!"
92
+ msgstr ""
93
+
94
+ #: css-js-toolbox.php:1033
95
+ msgid "CSS & JAVASCRIPT TOOLBOX - INSTRUCTIONS AND DEMO"
96
+ msgstr ""
97
+
98
+ #: css-js-toolbox.php:1034
99
+ msgid ""
100
+ "Feel free to delete all of this text at any time. For more information, "
101
+ "please click 'Hints & Tips'"
102
+ msgstr ""
103
+
104
+ #: css-js-toolbox.php:1035
105
+ msgid ""
106
+ "Write your CSS and JS code here, then apply it by using one of the tabs "
107
+ "(Pages, Categories, URL) from the panel on the right"
108
+ msgstr ""
109
+
110
+ #: css-js-toolbox.php:1036
111
+ msgid ""
112
+ "The example JavaScript code shown below will display an alert message box"
113
+ msgstr ""
114
+
115
+ #: css-js-toolbox.php:1037
116
+ msgid ""
117
+ "To see this code in action, lets click the \"Front Page\" checkbox from the "
118
+ "panel on the right"
119
+ msgstr ""
120
+
121
+ #: css-js-toolbox.php:1038
122
+ msgid ""
123
+ "Click the blue 'Save All Changes' button, then click the Front Page "
124
+ "navigation icon to open the page in a new window"
125
+ msgstr ""
126
+
127
+ #: css-js-toolbox.php:1039
128
+ msgid "Have fun!!!"
129
+ msgstr ""
130
+
131
+ #: modules/v03e/views/error-note.html.tmpl:3 modules/v03e/v03e.php:72
132
+ msgid ""
133
+ "Current code block contains errors!!! Click here to show or hide the details"
134
+ msgstr ""
135
+
136
+ #: modules/v03e/views/error-note.html.tmpl:8
137
+ msgid ""
138
+ "You have upgraded from an older version, and unfortunately the previous "
139
+ "version introduced an error, which needs correcting."
140
+ msgstr ""
141
+
142
+ #: modules/v03e/views/error-note.html.tmpl:9
143
+ msgid ""
144
+ "Inspect your code blocks and you may notice extra back slash characters "
145
+ "occurring before quotes, double quotes and other back slashes."
146
+ msgstr ""
147
+
148
+ #: modules/v03e/views/error-note.html.tmpl:10
149
+ msgid ""
150
+ "Due to a bug, these 'additional' back slash characters were added when code "
151
+ "was inserted from the CSS or JS Template drop-down boxes."
152
+ msgstr ""
153
+
154
+ #: modules/v03e/views/error-note.html.tmpl:11
155
+ msgid ""
156
+ "In this latest version, we have created an error detection and correction "
157
+ "system to help you to fix these errors."
158
+ msgstr ""
159
+
160
+ #: modules/v03e/views/error-note.html.tmpl:12
161
+ #, php-format
162
+ msgid ""
163
+ "Please note that the error detection and correction system can not be 100% "
164
+ "certain if the detected error is actually an error or not."
165
+ msgstr ""
166
+
167
+ #: modules/v03e/views/error-note.html.tmpl:13
168
+ msgid ""
169
+ "Therefore, you would need to assist this error system by confirming whether "
170
+ "the back slash character should be there or not."
171
+ msgstr ""
172
+
173
+ #: modules/v03e/views/error-note.html.tmpl:14
174
+ msgid ""
175
+ "Consider backing up your code blocks by clicking the Backup link in the top "
176
+ "right corner beforehand, then you can restore your code blocks."
177
+ msgstr ""
178
+
179
+ #: modules/v03e/views/error-note.html.tmpl:15
180
+ msgid ""
181
+ "Clicking 'Clean up' will clean extra back slash errors and you can see this "
182
+ "happen in the editor window. For a video on how this works, please click:"
183
+ msgstr ""
184
+
185
+ #: modules/v03e/views/error-note.html.tmpl:15
186
+ msgid "Help Video"
187
+ msgstr ""
188
+
189
+ #: modules/v03e/views/error-note.html.tmpl:16
190
+ msgid ""
191
+ "This error system for detecting and correcting code blocks supports the "
192
+ "following error types:"
193
+ msgstr ""
194
+
195
+ #: modules/v03e/views/error-note.html.tmpl:24
196
+ #: modules/v03e/views/scan-message.html.tmpl:2
197
+ msgid "displayName"
198
+ msgstr ""
199
+
200
+ #: modules/v03e/views/error-note.html.tmpl:24
201
+ msgid "description"
202
+ msgstr ""
203
+
204
+ #: modules/v03e/views/error-note.html.tmpl:35
205
+ msgid "Dismiss"
206
+ msgstr ""
207
+
208
+ #: modules/v03e/views/error-note.html.tmpl:36
209
+ msgid "Re-scan"
210
+ msgstr ""
211
+
212
+ #: modules/v03e/views/error-note.html.tmpl:37
213
+ msgid "Clean up"
214
+ msgstr ""
215
+
216
+ #: modules/v03e/views/scan-message.html.tmpl:2
217
+ msgid "Detected error"
218
+ msgstr ""
219
+
220
+ #: modules/v03e/views/scan-message.html.tmpl:19
221
+ msgid "For the location of each match, click on the item."
222
+ msgstr ""
223
+
224
+ #: modules/v03e/v03e.php:62
225
+ msgid ""
226
+ "After cleaning up this code block, you will not be able to scan the code "
227
+ "again."
228
+ msgstr ""
229
+
230
+ #: modules/v03e/v03e.php:63
231
+ msgid "Would you like to clean up the current code block?"
232
+ msgstr ""
233
+
234
+ #: modules/v03e/v03e.php:64 modules/tools/views/tools-bar.html.tmpl:6
235
+ msgid "Nothing is saved until you click the \"Save Changes\" button."
236
+ msgstr ""
237
+
238
+ #: modules/v03e/v03e.php:65
239
+ msgid "The scan is outdated."
240
+ msgstr ""
241
+
242
+ #: modules/v03e/v03e.php:66
243
+ msgid "This is may be a result of changing the block code."
244
+ msgstr ""
245
+
246
+ #: modules/v03e/v03e.php:67
247
+ msgid "Please rescan the code and then click cleanUp."
248
+ msgstr ""
249
+
250
+ #: modules/v03e/v03e.php:68
251
+ msgid ""
252
+ "After dismissing this message you'll never be able to scan/clean this block "
253
+ "again"
254
+ msgstr ""
255
+
256
+ #: modules/v03e/v03e.php:69
257
+ msgid "Are you sure?"
258
+ msgstr ""
259
+
260
+ #: modules/v03e/v03e.php:70
261
+ msgid "Block code is now clean"
262
+ msgstr ""
263
+
264
+ #: modules/v03e/v03e.php:71
265
+ msgid "Nothing saved untill \"Save all changes\" button is clicked."
266
+ msgstr ""
267
+
268
+ #: modules/v03e/v03e.php:73
269
+ msgid "Block code has been changed, scan is outdated!!!"
270
+ msgstr ""
271
+
272
+ #: modules/v03e/v03e.php:74
273
+ msgid "Would you like to rescan the code?"
274
+ msgstr ""
275
+
276
+ #: modules/tools/views/tools-bar.html.tmpl:5
277
+ msgid "You have now restored the code blocks from the current backup."
278
+ msgstr ""
279
+
280
+ #: modules/tools/views/tools-bar.html.tmpl:7
281
+ msgid ""
282
+ "To revert back to the previous code blocks and discard this action, simply "
283
+ "click the Cancel Restoring link."
284
+ msgstr ""
285
+
286
+ #: modules/tools/views/tools-bar.html.tmpl:10
287
+ #: modules/tools/views/tools-bar.html.tmpl:16
288
+ msgid "CSS & Javascript Database:"
289
+ msgstr ""
290
+
291
+ #: modules/tools/views/tools-bar.html.tmpl:10
292
+ #: modules/tools/views/tools-bar.html.tmpl:16
293
+ #: modules/tools/views/backupform.html.tmpl:25
294
+ msgid "Backup"
295
+ msgstr ""
296
+
297
+ #: modules/tools/views/tools-bar.html.tmpl:10
298
+ msgid "Cancel Restoring"
299
+ msgstr ""
300
+
301
+ #: modules/tools/views/tools-bar.html.tmpl:16
302
+ #: modules/tools/views/backupform.html.tmpl:27
303
+ msgid "Restore"
304
+ msgstr ""
305
+
306
+ #: modules/tools/views/backupform.html.tmpl:8
307
+ msgid "on"
308
+ msgstr ""
309
+
310
+ #: modules/tools/views/backupform.html.tmpl:8
311
+ msgid "by"
312
+ msgstr ""
313
+
314
+ #: modules/tools/views/backupform.html.tmpl:29
315
+ #: views/snippets/blockname.html.tmpl:8 views/snippets/newcode.html.tmpl:24
316
+ msgid "Cancel"
317
+ msgstr ""
318
+
319
+ #: modules/tools/tools.php:49
320
+ msgid "Content change has been detected."
321
+ msgstr ""
322
+
323
+ #: modules/tools/tools.php:50
324
+ msgid "It seems that some changes made in the blocks code."
325
+ msgstr ""
326
+
327
+ #: modules/tools/tools.php:51
328
+ msgid "This changes won't be saved in the backup."
329
+ msgstr ""
330
+
331
+ #: modules/tools/tools.php:52
332
+ msgid "To save these changes click \"Save Changes\" and then click backup."
333
+ msgstr ""
334
+
335
+ #: modules/tools/tools.php:53
336
+ msgid "Would you to discard these changes from the backup?"
337
+ msgstr ""
338
+
339
+ #: modules/tools/tools.php:54
340
+ msgid "Could not backup the database, please try again."
341
+ msgstr ""
342
+
343
+ #: modules/tools/tools.php:55
344
+ msgid "Server not responding!!! Please try again."
345
+ msgstr ""
346
+
347
+ #: modules/tools/tools.php:56
348
+ msgid "No backup available!!!"
349
+ msgstr ""
350
+
351
+ #: views/snippets/wpobjectslist.tmpl:7
352
+ msgid "Pages"
353
+ msgstr ""
354
+
355
+ #: views/snippets/wpobjectslist.tmpl:8
356
+ msgid "Categories"
357
+ msgstr ""
358
+
359
+ #: views/snippets/wpobjectslist.tmpl:9
360
+ msgid "URL List"
361
+ msgstr ""
362
+
363
+ #: views/snippets/wpobjectslist.tmpl:12
364
+ msgid "Add this CSS/JS code to ?"
365
+ msgstr ""
366
+
367
+ #: views/snippets/wpobjectslist.tmpl:16
368
+ msgid "Front Page"
369
+ msgstr ""
370
+
371
+ #: views/snippets/wpobjectslist.tmpl:21
372
+ msgid "All Posts"
373
+ msgstr ""
374
+
375
+ #: views/snippets/wpobjectslist.tmpl:26
376
+ msgid "All Pages"
377
+ msgstr ""
378
+
379
+ #: views/snippets/wpobjectslist.tmpl:33
380
+ msgid "Add this CSS/JS code to category page?"
381
+ msgstr ""
382
+
383
+ #: views/snippets/wpobjectslist.tmpl:39
384
+ msgid "Add one URL per line (include http://)"
385
+ msgstr ""
386
+
387
+ #: views/snippets/block.tmpl:8
388
+ msgid "CSS Template"
389
+ msgstr ""
390
+
391
+ #: views/snippets/block.tmpl:10
392
+ msgid "Insert selected CSS Template"
393
+ msgstr ""
394
+
395
+ #: views/snippets/block.tmpl:10 views/snippets/block.tmpl:19
396
+ msgid "Insert Code"
397
+ msgstr ""
398
+
399
+ #: views/snippets/block.tmpl:11
400
+ msgid "Add New CSS Code Template"
401
+ msgstr ""
402
+
403
+ #: views/snippets/block.tmpl:11 views/snippets/block.tmpl:20
404
+ msgid "New"
405
+ msgstr ""
406
+
407
+ #: views/snippets/block.tmpl:12
408
+ msgid "Edit CSS Code Template"
409
+ msgstr ""
410
+
411
+ #: views/snippets/block.tmpl:12 views/snippets/block.tmpl:21
412
+ msgid "Edit"
413
+ msgstr ""
414
+
415
+ #: views/snippets/block.tmpl:13
416
+ msgid "Delete selected CSS Template"
417
+ msgstr ""
418
+
419
+ #: views/snippets/block.tmpl:13 views/snippets/block.tmpl:22
420
+ msgid "Delete Code"
421
+ msgstr ""
422
+
423
+ #: views/snippets/block.tmpl:17
424
+ msgid "JS Template"
425
+ msgstr ""
426
+
427
+ #: views/snippets/block.tmpl:19
428
+ msgid "Insert selected JavaScript Template"
429
+ msgstr ""
430
+
431
+ #: views/snippets/block.tmpl:20
432
+ msgid "Add New JavaScript Code Template"
433
+ msgstr ""
434
+
435
+ #: views/snippets/block.tmpl:21
436
+ msgid "Edit JS Code Template"
437
+ msgstr ""
438
+
439
+ #: views/snippets/block.tmpl:22
440
+ msgid "Delete selected JavaScript Template"
441
+ msgstr ""
442
+
443
+ #: views/snippets/block.tmpl:59
444
+ msgid "Location"
445
+ msgstr ""
446
+
447
+ #: views/snippets/block.tmpl:59
448
+ msgid "Hook"
449
+ msgstr ""
450
+
451
+ #: views/snippets/block.tmpl:63
452
+ msgid "Header"
453
+ msgstr ""
454
+
455
+ #: views/snippets/block.tmpl:64
456
+ msgid "Footer"
457
+ msgstr ""
458
+
459
+ #: views/snippets/block.tmpl:77
460
+ msgid "Scripts Autoload"
461
+ msgstr ""
462
+
463
+ #: views/snippets/block.tmpl:77
464
+ msgid "Automatically load Wordpress build-in scripts."
465
+ msgstr ""
466
+
467
+ #: views/snippets/block.tmpl:77
468
+ msgid "Embedded Scripts"
469
+ msgstr ""
470
+
471
+ #: views/snippets/block.tmpl:82
472
+ msgid "Click for"
473
+ msgstr ""
474
+
475
+ #: views/snippets/block.tmpl:83
476
+ msgid "Click for Hints &amp; Tips"
477
+ msgstr ""
478
+
479
+ #: views/snippets/block.tmpl:83
480
+ msgid "Hints"
481
+ msgstr ""
482
+
483
+ #: views/snippets/block.tmpl:83
484
+ msgid "Tips"
485
+ msgstr ""
486
+
487
+ #: views/snippets/block.tmpl:88
488
+ msgid "Upgrade to"
489
+ msgstr ""
490
+
491
+ #: views/snippets/block.tmpl:89
492
+ msgid "CSS & Javascript Toolbox"
493
+ msgstr ""
494
+
495
+ #: views/snippets/block.tmpl:93 views/snippets/newcode.html.tmpl:20
496
+ msgid "Save Changes"
497
+ msgstr ""
498
+
499
+ #: views/snippets/block.tmpl:94
500
+ msgid "Delete This Block"
501
+ msgstr ""
502
+
503
+ #: views/snippets/block.tmpl:95
504
+ msgid "Edit Block Name"
505
+ msgstr ""
506
+
507
+ #: views/snippets/blockname.html.tmpl:5
508
+ msgid "Block Name"
509
+ msgstr ""
510
+
511
+ #: views/snippets/blockname.html.tmpl:10 views/snippets/newcode.html.tmpl:22
512
+ #: views/snippets/scripts.html.tmpl:34
513
+ msgid "Close"
514
+ msgstr ""
515
+
516
+ #: views/snippets/blockname.html.tmpl:12 views/snippets/newcode.html.tmpl:29
517
+ #: views/snippets/scripts.html.tmpl:35
518
+ msgid "Working"
519
+ msgstr ""
520
+
521
+ #: views/snippets/blockname.html.tmpl:15
522
+ msgid "Block names are useful to keep your code blocks managed and organised."
523
+ msgstr ""
524
+
525
+ #: views/snippets/blockname.html.tmpl:16
526
+ msgid ""
527
+ "Please type a relevant name that describes what your block does, then click "
528
+ "Save."
529
+ msgstr ""
530
+
531
+ #: views/snippets/newcode.html.tmpl:13
532
+ msgid "Title"
533
+ msgstr ""
media/icons/add_code.png DELETED
Binary file
media/icons/delete_code.png DELETED
Binary file
media/icons/external_link.gif DELETED
Binary file
media/icons/insert_code.png DELETED
Binary file
modules/tools/public/css/style.css ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ #cjt-tools{ text-align: right; margin-bottom: 4px;}
2
+ #cjtoolbox_tools_backup_form h3 span.name,
3
+ #cjtoolbox_tools_backup_form h3 span.time,
4
+ #cjtoolbox_tools_backup_form h3 span.author { background-color: snow; }
5
+ #cjtoolbox_tools_backup_form li.item ul.more-details{ display: none; }
6
+ #cjtoolbox_tools_backup_form li.item ul.more-details{ display: none; }
7
+ #cjtoolbox_tools_backup_form .blocks-list { height: 500px; max-height: 500px; overflow: auto; }
8
+ .animated-link img { border: none; }
9
+ .cjt-tools-notice { font-size: 16px; line-height: 20px; color:#BF6B19; padding: 10px 10px 10px 10px; margin-bottom: 10px; background-color: #FAF4EE; border: 1px solid; }
modules/tools/public/images/link-loading.gif ADDED
Binary file
modules/tools/public/js/tools.js ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @version
3
+ */
4
+
5
+ /**
6
+ *
7
+ */
8
+ var CJTTools = null;
9
+
10
+ /**
11
+ *
12
+ *
13
+ *
14
+ */
15
+ jQuery(function($) {
16
+ CJTTools = {
17
+
18
+ /**
19
+ *
20
+ *
21
+ *
22
+ */
23
+ linkAnimationImage : ajaxurl.replace('wp-admin/admin-ajax.php', 'wp-content/plugins/css-javascript-toolbox/modules/tools/public/images/link-loading.gif'),
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ */
30
+ securityToken : $('#cjsecurity').val(),
31
+
32
+ /**
33
+ *
34
+ *
35
+ *
36
+ */
37
+ url : ajaxurl,
38
+
39
+ /**
40
+ *
41
+ *
42
+ *
43
+ */
44
+ backup : function() {
45
+ // Prompt saving changes.
46
+ if (contentHash.isChanged()) {
47
+ if (!confirm(CJTToolsLocalization.backupConfirm)) {
48
+ return;
49
+ }
50
+ }
51
+ var backupInfo = CJTTools.getBackupInfo();
52
+ if (backupInfo != null) { // Only when request success.
53
+ if (backupInfo.has) {
54
+ CJTTools.showBackupForm({task : 'backup'});
55
+ }
56
+ else {
57
+ CJTTools.backupDatabase();
58
+ }
59
+ }
60
+ },
61
+
62
+ /**
63
+ *
64
+ *
65
+ *
66
+ */
67
+ backupDatabase : function() {
68
+ var data = {
69
+ security : CJTTools.securityToken,
70
+ action : 'cjtoolbox_tools_backup',
71
+ backupName : prompt('Please enter Backup Name')
72
+ };
73
+ if (data.backupName) {
74
+ CJTTools.linkAnimate('cjt-tools-backup');
75
+ $.get(CJTTools.url, data).complete(function() {
76
+ CJTTools.linkStopAnimation('cjt-tools-backup');
77
+ }).error(function() {
78
+ alert(CJTToolsLocalization.couldNotBackup);
79
+ });
80
+ }
81
+ },
82
+
83
+ /**
84
+ * Callback when blocks data saved.
85
+ * @see admin.js for more details.
86
+ */
87
+ blocksDataSaved : function() {
88
+ CJTTools.cancelRestore();
89
+ },
90
+
91
+ /**
92
+ *
93
+ *
94
+ *
95
+ */
96
+ cancelRestore : function() {
97
+ var newLocation = document.location.href.replace(/\?.+/, '?page=cjtoolbox');
98
+ CJTTools.linkAnimate('cjt-tools-restore');
99
+ document.location.href = newLocation;
100
+ },
101
+
102
+ /**
103
+ *
104
+ *
105
+ *
106
+ */
107
+ getBackupInfo : function() {
108
+ var response = null;
109
+ var request = {
110
+ async : false,
111
+ data : {
112
+ security : CJTTools.securityToken,
113
+ action : 'cjtoolbox_tools_getBackupInfo'
114
+ }
115
+ };
116
+ $.ajax(CJTTools.url, request).error(function() {
117
+ alert(CJTToolsLocalization.serverNotResponding);
118
+ }).success(function(responseText) {
119
+ // We don't need to check error codes for now.
120
+ response = $.parseJSON(responseText).response;
121
+ });
122
+ return response;
123
+ },
124
+
125
+ /**
126
+ *
127
+ *
128
+ *
129
+ */
130
+ linkAnimate : function(id) {
131
+ var link = $('a#' + id);
132
+ var animateImage = new Image(); // Neew animation image.
133
+ var imageContainer = document.createElement('span');
134
+ var alreadyAnimated = ($('span#' + id + '-link-animation').get(0) != null);
135
+ if (!alreadyAnimated) {
136
+ // Set container properties.
137
+ imageContainer.id = id + '-link-animation';
138
+ imageContainer.className = 'animated-link';
139
+ imageContainer.style.display = 'inline-block';
140
+ imageContainer.style.width = link.get(0).offsetWidth + 'px';
141
+ imageContainer.style.height = link.get(0).offsetHeight + 'px';
142
+ imageContainer.style.textAlign = 'center';
143
+ // Set image properties.
144
+ animateImage.src = CJTTools.linkAnimationImage;
145
+ // Append image to the container.
146
+ imageContainer.appendChild(animateImage); // Add to the container.
147
+ // Replace link.
148
+ link.before(imageContainer);
149
+ link.hide();
150
+ }
151
+ },
152
+
153
+ /**
154
+ *
155
+ *
156
+ *
157
+ */
158
+ linkStopAnimation : function(id) {
159
+ var link = $('a#' + id);
160
+ var animatedImage = $('span#' + id + '-link-animation');
161
+ animatedImage.remove();
162
+ link.show();
163
+ },
164
+
165
+ /**
166
+ *
167
+ *
168
+ *
169
+ */
170
+ restore : function() {
171
+ var backupInfo = CJTTools.getBackupInfo();
172
+ if (backupInfo != null) { // Only when request success.
173
+ if (backupInfo.has) {
174
+ CJTTools.showBackupForm({task : 'restore'});
175
+ }
176
+ else {
177
+ alert(CJTToolsLocalization.noBackupAvailable);
178
+ }
179
+ }
180
+ },
181
+
182
+ /**
183
+ *
184
+ *
185
+ *
186
+ */
187
+ restoreDatabase : function() {
188
+ var newLocation = document.location.href.replace(/\?.+/, '?page=cjtoolbox&restore=true');
189
+ CJTTools.linkAnimate('cjt-tools-restore');
190
+ document.location.href = newLocation;
191
+ },
192
+
193
+ /**
194
+ *
195
+ *
196
+ *
197
+ */
198
+ showBackupForm : function(requestData) {
199
+ requestData = (requestData == undefined) ? {} : requestData;
200
+ requestData.security = CJTTools.securityToken;
201
+ requestData.action = 'cjtoolbox_request_template';
202
+ requestData.name = 'tools_backupform';
203
+ requestData.width = 500;
204
+ requestData.height = 600;
205
+ var formURL = CJTTools.url + '?' + $.param(requestData);
206
+ tb_show('Current Backup', formURL);
207
+ }
208
+
209
+ }; // End CJTTools.
210
+
211
+ /// Misc ///
212
+
213
+ // Backup form blocks list.
214
+ $('#cjtoolbox_tools_backup_form ul.blocks-list li.item a.block-link').live('click', function(event) {
215
+ var link = $(this);
216
+ var detailsToToggle = link.next();
217
+ var list = $('#cjtoolbox_tools_backup_form ul.blocks-list li.item ul.more-details');
218
+ // Hide all other items except this.
219
+ list.each(function() {
220
+ if (this !== detailsToToggle.get(0)) {
221
+ $(this).hide();
222
+ }
223
+ });
224
+ // Toggle current item.
225
+ detailsToToggle.toggle();
226
+ });
227
+
228
+ // Register callback when data saved.
229
+ if (/restore\=true/.test(location.search)) {
230
+ var saveDataCb = ['CJTTools', 'blocksDataSaved']
231
+ cjt_data_saved_callbacks.push(saveDataCb);
232
+ // When restoring from the database clear content hash.
233
+ }
234
+ });
modules/tools/tools.php ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @version $Id ; v0.3e.php 16:33:02 07:02:2012 Ahmed Said ;
4
+ */
5
+
6
+ /**
7
+ * Provide error Blocks CODE detection and correction
8
+ * for the old version plugin.
9
+ *
10
+ * @author Ahmed Said
11
+ */
12
+ class CJTTools extends CJTModuleBase{
13
+
14
+ /**
15
+ * Backups Wordpress option name.
16
+ */
17
+ const BACKUPS_OPTION_NAME = 'cjtoolbox_tools_backups';
18
+
19
+ /**
20
+ * Allowed ajax action names.
21
+ *
22
+ * @var array
23
+ */
24
+ private static $actions = array(
25
+ 'api_getBackupInfo',
26
+ 'api_backup',
27
+ );
28
+
29
+ /**
30
+ * Create CJTV03Error object.
31
+ *
32
+ * @param array Modul info struct.
33
+ * @return void
34
+ */
35
+ public function __construct($moduleInfo) {
36
+ parent::__construct($moduleInfo, true);
37
+ add_action('cjt_upgraded', array($this, 'pluginUpgrade'));
38
+ }
39
+
40
+ /**
41
+ * Override cssJSToolbox::admin_print_scripts method.
42
+ */
43
+ public function admin_print_scripts() {
44
+ // Enqueue cssJSToolbox scripts.
45
+ $this->cjToolbox->admin_print_scripts();
46
+ // Enquque additional scripts.
47
+ wp_enqueue_script(CJTOOLBOX_NAME . '-tools-tools', $this->getJSFileURL('tools.js'));
48
+ $strings = array(
49
+ 'backupConfirm' => __('Content change has been detected.') . "\n\n" .
50
+ __('It seems that some changes made in the blocks code.') . "\n\n" .
51
+ __('This changes won\'t be saved in the backup.') . "\n\n" .
52
+ __('To save these changes click "Save Changes" and then click backup.') . "\n\n" .
53
+ __('Would you to discard these changes from the backup?'),
54
+ 'couldNotBackup' => __('Could not backup the database, please try again.'),
55
+ 'serverNotResponsing' => __('Server not responding!!! Please try again.'),
56
+ 'noBackupAvailable' => __('No backup available!!!')
57
+ );
58
+ wp_localize_script(CJTOOLBOX_NAME . '-tools-tools', 'CJTToolsLocalization', $strings);
59
+ }
60
+
61
+ /**
62
+ * Override cssJSToolbox::ajax_request_template method.
63
+ */
64
+ public function ajax_request_template() {
65
+ // Make sure the requested template is belongs to this module.
66
+ $templateName = $_GET['name'];
67
+ $templateNameComponents = array();
68
+ if (preg_match('/tools_(.+)/', $templateName, $templateNameComponents)) {
69
+ // Remove module name from template name.
70
+ $_GET['name'] = $templateNameComponents[1];
71
+ $this->cjToolbox->ajax_request_template($this->getPath('views'), array('tools' => $this));
72
+ }
73
+ else {
74
+ $this->cjToolbox->ajax_request_template();
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Override cssJSToolbox::admin_print_scripts method.
80
+ */
81
+ public function admin_print_styles() {
82
+ // Enqueue cssJSToolbox scripts.
83
+ $this->cjToolbox->admin_print_styles();
84
+ // Enquque additional scripts.
85
+ wp_enqueue_style(CJTOOLBOX_NAME . '-tools-tools', $this->getCSSFileURL('style.css'));
86
+ }
87
+
88
+ /**
89
+ * Dispatch ajax request and prepare the response.
90
+ *
91
+ * @return void
92
+ */
93
+ public function api() {
94
+ // Check if pemitted.
95
+ check_ajax_referer('cjtoolbox-admin', 'security');
96
+ // prepare the response in case dispatching failed.
97
+ $response = array(
98
+ 'code' => 0x00,
99
+ 'message' => 'Dispatching',
100
+ 'response' => array(),
101
+ );
102
+ // Get method name from the action name.
103
+ $action = current_filter();
104
+ $actionComponents = array();
105
+ if (preg_match('/_tools_(\w+)$/', $action, $actionComponents)) {
106
+ $methodName = "api_{$actionComponents[1]}";
107
+ // Restrict access.
108
+ if (in_array($methodName, self::$actions)) {
109
+ // Dispatch the call.
110
+ $response['code'] = 0x01;
111
+ $response['response'] = $this->$methodName($_POST);
112
+ }
113
+ else {
114
+ $response['code'] = 0xFF;
115
+ }
116
+ }
117
+ header('Content-Type: text/plain');
118
+ $responseJSON = json_encode($response);
119
+ die($responseJSON);
120
+ }
121
+
122
+ /**
123
+ * Ajax method for backup the database.
124
+ *
125
+ * @return array Response array.
126
+ */
127
+ protected function api_backup($name = null, $author = null) {
128
+ global $current_user;
129
+ // When called directely/internally
130
+ // it may take the author as paramater.
131
+ $author = $author ? $author : $current_user->display_name;
132
+ $name = $name ? $name : trim($_GET['backupName']);
133
+ $backup = array(
134
+ 'time' => date('h:i:s Y:M:d', time()),
135
+ 'name' => $name,
136
+ 'author' => $author,
137
+ 'data' => $this->cjToolbox->getData(),
138
+ );
139
+ // Wrap in array. We may alow multiple backups in the future.
140
+ update_option(self::BACKUPS_OPTION_NAME, array($backup));
141
+ // Response to the rquest.
142
+ $response = array(
143
+ 'backName' => $_GET['backupName'],
144
+ 'success' => true,
145
+ );
146
+ return $response;
147
+ }
148
+
149
+ /**
150
+ * Ajax method for get backup info.
151
+ *
152
+ * @return array Response array.
153
+ */
154
+ protected function api_getBackupInfo() {
155
+ $backups = $this->getAvailableBackups();
156
+ $response = array('has' => !empty($backups));
157
+ return $response;
158
+ }
159
+
160
+ /**
161
+ * Display tools bar.
162
+ * Callback for cjt_post_body_before_blocks.
163
+ */
164
+ public function displayToolBar() {
165
+ $toolbar = $this->getView('tools-bar', array());
166
+ echo $toolbar;
167
+ }
168
+
169
+ /**
170
+ * Get available backups.
171
+ *
172
+ */
173
+ public function getAvailableBackups() {
174
+ $backups = get_option(self::BACKUPS_OPTION_NAME);
175
+ return is_array($backups) ? $backups : array();
176
+ }
177
+
178
+ /**
179
+ * Get module instance.
180
+ *
181
+ * @see __construct for parameters info.
182
+ * @return CJTVTools Module instance.
183
+ */
184
+ public static function getInstance($moduleInfo) {
185
+ return new CJTTools($moduleInfo);
186
+ }
187
+
188
+ /**
189
+ * Callback for cjt_upgrade hook.
190
+ */
191
+ public function pluginUpgrade() {
192
+ // Create a backup when the Plugin upgraded.
193
+ $this->api_backup('Upgrading', 'system');
194
+ }
195
+
196
+ /**
197
+ * Restoring blocks from the last backup.
198
+ *
199
+ * Callback for cjt_blocks_data filter.
200
+ *
201
+ * @return array Blocks data.
202
+ */
203
+ public function restore($blocksData) {
204
+ $backups = $this->getAvailableBackups();
205
+ $blocksData = $backups[0]['data']; // For now we've only one backup.
206
+ return $blocksData;
207
+ }
208
+
209
+ /**
210
+ * Override cssJSToolbox::start_plugin method.
211
+ */
212
+ public function start_plugin() {
213
+ add_action('cjt_post_body_before_blocks', array($this, 'displayToolBar'));
214
+ add_action('wp_ajax_cjtoolbox_tools_getBackupInfo', array($this, 'api'));
215
+ add_action('wp_ajax_cjtoolbox_tools_backup', array($this, 'api'));
216
+ // bind restore hook.
217
+ if (isset($_GET['restore']) && $_GET['restore']) {
218
+ add_filter('cjt_blocks_data', array($this, 'restore'));
219
+ }
220
+ $this->cjToolbox->start_plugin();
221
+ }
222
+
223
+ } // End class.
224
+
225
+ // Put the module in action.
226
+ return CJTTools::getInstance($module);
modules/tools/views/backupform.html.tmpl ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="cjtoolbox_tools_backup_form">
2
+ <?php
3
+ // pleasd remember the context is the cssJSToolbox class not CJTTooks class.
4
+ $backups = $tools->getAvailableBackups();
5
+ foreach ($backups as $index => $backup) :
6
+ ?>
7
+ <div id="backup-<?php echo $index ?>">
8
+ <h3><span class="name"><?php echo $backup['name'] ?></span> <?php echo _e('on') ?> <span class="time"><?php echo $backup['time'] ?></span> <?php _e('by') ?> <span class="author"><?php echo $backup['author'] ?></span></h3>
9
+ <ul class="blocks-list">
10
+ <?php
11
+ foreach ($backup['data'] as $blockId => $block) :
12
+ ?>
13
+ <li class="item">
14
+ <a class="block-link" href="#"><?php echo $this->getBlockName($block, $blockId, 'Block #') ?></a>
15
+ <ul class="more-details">
16
+ <li><textarea style="width:98%;height:300px"><?php echo $block['code'] ?></textarea></li>
17
+ </ul>
18
+ </li>
19
+ <?php
20
+ endforeach;
21
+ ?>
22
+ </ul>
23
+ <div class="buttons">
24
+ <?php if ($_GET['task'] == 'backup') : ?>
25
+ <input type="button" onclick="CJTTools.backupDatabase();tb_remove();" value="<?php _e('Backup') ?>" />
26
+ <?php else : ?>
27
+ <input type="button" onclick="CJTTools.restoreDatabase();" value="<?php _e('Restore') ?>" />
28
+ <?php endif; ?>
29
+ <input type="button" onclick="tb_remove();" value="<?php _e('Cancel') ?>" />
30
+ </div>
31
+ </div>
32
+ <?php
33
+ endforeach;
34
+ ?>
35
+ </div>
modules/tools/views/tools-bar.html.tmpl ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if (isset($_GET['restore']) && $_GET['restore']) :
3
+ ?>
4
+ <div class="cjt-tools-notice">
5
+ <p><?php _e('You have now restored the code blocks from the current backup.') ?></p>
6
+ <p><?php _e('Nothing is saved until you click the "Save Changes" button.') ?></p>
7
+ <p><?php _e('To revert back to the previous code blocks and discard this action, simply click the Cancel Restoring link.') ?></p>
8
+ </div>
9
+ <div id="cjt-tools">
10
+ <?php _e('CSS & Javascript Database:') ?> <a id="cjt-tools-backup" href="javascript:void('#');" onclick="CJTTools.backup();"><?php _e('Backup') ?></a> | <a id="cjt-tools-restore" href="javascript:void('#');" onclick="CJTTools.cancelRestore();"><?php _e('Cancel Restoring') ?></a>
11
+ </div>
12
+ <?php
13
+ else :
14
+ ?>
15
+ <div id="cjt-tools">
16
+ <?php _e('CSS & Javascript Database:') ?> <a id="cjt-tools-backup" href="javascript:void('#');" onclick="CJTTools.backup();"><?php _e('Backup') ?></a> | <a id="cjt-tools-restore" href="javascript:void('#');" onclick="CJTTools.restore();"><?php _e('Restore') ?></a>
17
+ </div>
18
+ <?php
19
+ endif;
20
+ ?>
modules/v03e/public/css/style.css ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .error-list{border: 1px solid #999; overflow: auto;padding: 10px 0; max-height: 140px;}
3
+ .error-list li{cursor: pointer;list-style: none;background: none;margin-left: 20px; color: black;}
4
+ .error-list .selected{background-color: #EFEFEF;}
5
+ .v03e-block-message{width:99%;}
6
+ .notification-bar p{cursor: pointer; font-weight: bold;font-size: 14px;}
7
+ .message-area{display: none;background-color:#fff; padding: 5px 5px 5px 5px; border: solid 1px #ccc;}
8
+ .message-area .commands {background-color: white;} /* Links */
9
+ .v03e-loader{display: none;}
10
+ .warning-message{color:#97854e; font-weight: bold;}
11
+ .error-message p {color: black;}
12
+ p.matches-note{color: gray;}
13
+
14
+ .notification-bar.notify-error {
15
+ background: #FFBFBF url(../images/error.png) center no-repeat;
16
+ background-position: 15px 50%;
17
+ text-align: left;
18
+ padding: 0px 0px 0px 45px;
19
+ border-top: 2px solid #FF2424;
20
+ border-bottom: 2px solid #FF2424;color:red;
21
+ }
22
+ .message-area .txt-error{ color:#F00;}
23
+
24
+ .notification-bar.notify-warning {
25
+ background: #ffe38f url(../images/warning.png) center no-repeat;
26
+ background-position: 15px 50%;
27
+ text-align: left;
28
+ padding: 0px 0px 0px 45px;
29
+ border-top: 2px solid #fece3e;
30
+ border-bottom: 2px solid #fece3e;color:#97854e;
31
+ }
32
+ .message-area .txt-warning{ color:#97854e;}
33
+
34
+ ul.v0e3-error-types-list{font-weight: bolder; padding-left: 40px;list-style-type: disc;}
modules/v03e/public/images/error.png ADDED
Binary file
modules/v03e/public/images/warning.png ADDED
Binary file
modules/v03e/public/js/edc.js ADDED
@@ -0,0 +1,368 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ *
3
+ *
4
+ */
5
+ var v03e = {};
6
+
7
+ /**
8
+ *
9
+ *
10
+ *
11
+ */
12
+ jQuery(function($){
13
+ /**
14
+ *
15
+ *
16
+ *
17
+ */
18
+ v03e = {
19
+
20
+ errorTypesParameters : {
21
+ 'error' : {css : {className : 'notify-error'}},
22
+ 'warning' : {css : {className : 'notify-warning'}}
23
+ },
24
+
25
+ /**
26
+ *
27
+ *
28
+ *
29
+ */
30
+ cleanUp : function(blockId) {
31
+ var blockData = v03e.getBlockMetaData(blockId);
32
+ var meta = blockData.meta;
33
+ var matchLength = 0;
34
+ var matchOffset = 0;
35
+ var matchEndOffset = 0;
36
+ var uncleanedCode = blockData.code.val();
37
+ var originalCodeLength = uncleanedCode.length;
38
+ var uncleanedMatch = '';
39
+ var cleanedMatch = '';
40
+ var cleanedCode = '';
41
+ var correctionRoutine = 'correctMatch_' + meta.errorType;
42
+
43
+ $.each(meta.matchesList, function() {
44
+ offsetDifference = originalCodeLength - uncleanedCode.length;
45
+ matchOffset = this[0] - offsetDifference;
46
+ uncleanedMatch = this[1];
47
+ if (this[2] == true) { // If user tick the checkbox.
48
+ cleanedMatch = v03e[correctionRoutine](uncleanedMatch);
49
+ //cleanedMatch = uncleanedMatch.replace(errorExpression, '$1$2$1');
50
+ uncleanedCode = uncleanedCode.replace(uncleanedMatch, cleanedMatch);
51
+ matchLength = cleanedMatch.length;
52
+ }
53
+ else{
54
+ matchLength = uncleanedMatch.length;
55
+ }
56
+ // Put the cleaned match to the cleaned code.
57
+ matchEndOffset = matchOffset + matchLength;
58
+ cleanedCode += uncleanedCode.substr(0, matchEndOffset);
59
+ // Remove last match from unlcleaned code.
60
+ uncleanedCode = uncleanedCode.substr(matchEndOffset);
61
+ });
62
+ // The remaining code is considered as clean.
63
+ cleanedCode += uncleanedCode;
64
+ // Apply the cleaned code.
65
+ blockData.code.val(cleanedCode);
66
+ return blockData;
67
+ },
68
+
69
+
70
+ /**
71
+ *
72
+ *
73
+ *
74
+ */
75
+ cleanUpBlock : function(blockId) {
76
+ var doIt = confirm(CJTv03eLocalization.confirmCleanup);
77
+ if (doIt) {
78
+ var blockData = v03e.getBlockMetaData(blockId);
79
+ // Check if the scan is outdated.
80
+ var codeHash = hex_md5(blockData.code.val());
81
+ if (codeHash != blockData.meta._code_hash) {
82
+ alert(CJTv03eLocalization.CleanupScanIsOutdated);
83
+ }
84
+ else{
85
+ v03e.cleanUp(blockId);
86
+ v03e.nextError(blockId, false);
87
+ }
88
+ }
89
+ },
90
+
91
+ /**
92
+ *
93
+ *
94
+ *
95
+ */
96
+ correctMatch_error : function(match) {
97
+ var expression = /\\(\"|\')((?:\\\\\1|.)*)?\\\1/;
98
+ var cleanedMatch = match.replace(expression, '$1$2$1');
99
+ return cleanedMatch;
100
+ },
101
+
102
+ /**
103
+ *
104
+ *
105
+ *
106
+ */
107
+ correctMatch_warning : function(match) {
108
+ var slashCount = match.length;
109
+ var originalSlashCount = Math.floor(slashCount / 2);
110
+ var cleanedMatch = match.substr(0, originalSlashCount);
111
+ return cleanedMatch;
112
+ },
113
+
114
+ /**
115
+ *
116
+ *
117
+ *
118
+ */
119
+ createBlockHash : function(blockData) {
120
+ blockData = v03e.getBlockMetaData(blockData.blockId);
121
+ blockData.meta._code_hash_object.val(hex_md5(blockData.code.val()));
122
+ },
123
+
124
+ /**
125
+ *
126
+ *
127
+ *
128
+ */
129
+ dismiss : function(blockId, showMessage) {
130
+ var blockData = v03e.getBlockMetaData(blockId);
131
+ var dimissedErrorType = blockData.meta.errorType;
132
+ var dismissed = false;
133
+ if (!showMessage || confirm(CJTv03eLocalization.confirmDismiss)) {
134
+ dismissed = true;
135
+ // Mark error type as dimissed.
136
+ var dismissed = '<input type="hidden" name="cjtoolbox[' + blockId + '][meta][v03e][dismissed-' + dimissedErrorType + ']" value="true" />';
137
+ blockData.manageForm.append(dismissed);
138
+ }
139
+ return dismissed;
140
+ },
141
+
142
+ /**
143
+ *
144
+ *
145
+ *
146
+ */
147
+ getBlockBoxData : function(blockId) {
148
+ var boxId = blockId + 1;
149
+ var blockSelector = '#cjtoolbox-' + boxId;
150
+ var manageForm = $('#cjtoolbox_form');
151
+ var blockBox = $(blockSelector);
152
+ var data = {
153
+ security: manageForm.find('input:hidden[name="security"]').val(),
154
+ blockId: blockId,
155
+ boxId: boxId,
156
+ selector: blockSelector,
157
+ blockBox: blockBox,
158
+ code: blockBox.find('.datablock textarea'),
159
+ manageForm: manageForm
160
+ }
161
+ return data;
162
+ },
163
+
164
+ /**
165
+ *
166
+ *
167
+ *
168
+ */
169
+ getBlockMetaData : function(blockId) {
170
+ var blockData = this.getBlockBoxData(blockId);
171
+ var metaFieldSelector = 'cjtoolbox[' + blockData.blockId + '][meta][v03e]';
172
+ var matchesListSelector = 'input:hidden[id="' + metaFieldSelector + '[_list_json]' + '"]';
173
+ var matchesListJSON = blockData.blockBox.find(matchesListSelector).val();
174
+ var matchesList = $.parseJSON(matchesListJSON);
175
+ var matchSelected = null;
176
+ var blockMeta = {};
177
+ var otherMetaFields = ['name:allErrorTypes', 'name:errorType', 'id:_code_hash'];
178
+ // Matches list is a json list but we need to determing
179
+ // user selection too.
180
+ $.each(matchesList, function(index, match) {
181
+ currentMetaSelector = 'input:checkbox[name="' + metaFieldSelector + '[_list][' + index + '][1]' + '"]';
182
+ matchSelected = blockData.blockBox.find(currentMetaSelector).prop('checked');
183
+ // i:0 = Offset, i:1 = string match. Add user selection at index 2.
184
+ matchesList[index].push(matchSelected);
185
+ });
186
+ // Get simple types meta fields.
187
+ $.each(otherMetaFields, function() {
188
+ var metaFieldComponents = this.split(':');
189
+ currentMetaSelector = 'input:hidden[' + metaFieldComponents[0] + '="' + metaFieldSelector + '[' + metaFieldComponents[1] + ']' + '"]'
190
+ blockMeta[metaFieldComponents[1] + '_object'] = blockData.blockBox.find(currentMetaSelector);
191
+ blockMeta[metaFieldComponents[1]] = blockData.blockBox.find(currentMetaSelector).val();
192
+ });
193
+ blockMeta.allErrorTypes = $.parseJSON(blockMeta.allErrorTypes); // Serialized array.
194
+ blockMeta.matchesList = matchesList;
195
+ blockData.meta = blockMeta;
196
+ return blockData;
197
+ },
198
+
199
+ /**
200
+ *
201
+ *
202
+ *
203
+ *
204
+ */
205
+ getMessageArea : function(blockId) {
206
+ var blockData = v03e.getBlockBoxData(blockId);
207
+ var messageArea = blockData.blockBox.find('.v03e-block-message .error-message');
208
+ return messageArea;
209
+ },
210
+
211
+ /**
212
+ *
213
+ *
214
+ *
215
+ */
216
+ nextError : function(blockId, confirm) {
217
+ var blockData = v03e.getBlockMetaData(blockId);
218
+ var meta = blockData.meta;
219
+ var currentError = meta.errorType;
220
+ var errorIndex = meta.allErrorTypes.indexOf(currentError);
221
+ var nextErrorIndex = ++errorIndex;
222
+ var nextError = '';
223
+ if (v03e.dismiss(blockData.blockId, confirm)) {
224
+ if (nextErrorIndex == meta.allErrorTypes.length) { // No more error types.
225
+ // Remove error meta fields.
226
+ var errorMeta = ['errorType', 'allErrorTypes'];
227
+ $.each(errorMeta, function() {
228
+ var metaFieldSelector = 'input:hidden[name="cjtoolbox[' + blockId + '][meta][v03e][' + this + ']"]';
229
+ blockData.blockBox.find(metaFieldSelector).remove();
230
+ });
231
+ // Remove error message element.
232
+ var message = $('#v03e-error-note-block-' + blockId);
233
+ message.remove();
234
+ alert(CJTv03eLocalization.codeCleaned);
235
+ }
236
+ else{
237
+ nextError = meta.allErrorTypes[nextErrorIndex];
238
+ blockData.meta.errorType_object.val(nextError);
239
+ v03e.rescan(blockId);
240
+ }
241
+ }
242
+ },
243
+
244
+ /**
245
+ *
246
+ *
247
+ *
248
+ */
249
+ rescan : function(blockId) {
250
+ var url = ajaxurl;
251
+ var action = 'cjtoolbox_v03e_checkCode';
252
+ var blockData = v03e.getBlockMetaData(blockId);
253
+ var messageArea = v03e.getMessageArea(blockId);
254
+ var loader = $('#v03e-block-loader-' + blockId);
255
+ var data = {
256
+ security: blockData.security,
257
+ action: action,
258
+ blockId: blockId,
259
+ errorType: blockData.meta.errorType,
260
+ code: blockData.code.val()
261
+ };
262
+ messageArea.hide();
263
+ loader.show();
264
+ if (data.code) {
265
+ $.post(url, $.param(data), function(response) {
266
+ loader.hide();
267
+ if (response.has) {
268
+ messageArea.replaceWith(response.message);
269
+ v03e.createBlockHash(blockData);
270
+ v03e.setNotificationBarStyle(blockId, blockData.meta.errorType);
271
+ }
272
+ else {
273
+ v03e.nextError(blockId, false);
274
+ }
275
+ }, 'json');
276
+ }
277
+ else {
278
+ alert('Block has no code!!!');
279
+ }
280
+ },
281
+
282
+ /**
283
+ *
284
+ *
285
+ *
286
+ */
287
+ setNotificationBarStyle : function(blockId, errorType) {
288
+ var notificationBarSelector = '#v03e-error-note-block-' + blockId + ' .notification-bar';
289
+ var notificationBar = $(notificationBarSelector);
290
+ var errorTypeCSS = v03e.errorTypesParameters[errorType].css;
291
+ notificationBar.removeClass();
292
+ notificationBar.addClass('notification-bar notify-' + errorType);
293
+ }
294
+
295
+ } // End v03E class.
296
+
297
+ /**
298
+ * MISC
299
+ */
300
+
301
+ // Allow toggling the notification bar
302
+ $('.v03e-block-message .notification-bar p').click(function() {
303
+ var bar = $(this);
304
+ var messageArea = $('.message-area', bar.parent().parent());
305
+ messageArea.toggle('slow', function(){
306
+ if (this.style.display == 'block') {
307
+ bar.text(CJTv03eLocalization.errorBoxTitle);
308
+ }
309
+ else{
310
+ bar.text(CJTv03eLocalization.errorBoxTitle);
311
+ }
312
+ });
313
+ });
314
+
315
+ // Select matches string in the block code editor with
316
+ // user selection.
317
+ $('ul.error-list li').live('click', function(event) {
318
+ var li = $(this);
319
+ var ul = li.parent();
320
+ var blockId = parseInt(ul.get(0).className.match(/blockID\-(\d+)/)[1]);
321
+ var blockData = v03e.getBlockMetaData(blockId);
322
+ var codeEditor = blockData.code.get(0);
323
+ var matchOffset = parseInt(li.find('input:hidden').val());
324
+ var matchLength = li.find('input:checkbox').val().length;
325
+ // Check if the scan is outdated.
326
+ var codeHash = hex_md5(blockData.code.val());
327
+ if (codeHash != blockData.meta._code_hash) {
328
+ var rescan = confirm(CJTv03eLocalization.rescanOutdated);
329
+ if (rescan) {
330
+ v03e.rescan(blockId);
331
+ }
332
+ return;
333
+ }
334
+ ul.children().removeClass('selected');
335
+ li.toggleClass('selected');
336
+ if (codeEditor.createTextRange) { // IE
337
+ var selection = codeEditor.createTextRange();
338
+ selection.collapse(true);
339
+ selection.moveStart('character', matchOffset);
340
+ selection.moveEnd('character', matchLength);
341
+ selection.select();
342
+ }
343
+ else if (codeEditor.setSelectionRange){
344
+ // Opera exludes new lines from the selection.
345
+ // Selection is active on only on the printable characters.
346
+ if (window.navigator.userAgent.toLowerCase().indexOf('opera') != -1) {
347
+ var precedingText = codeEditor.value.substr(0, matchOffset);
348
+ // The lines count is the returned lines count - the first line (1).
349
+ var linesCount = precedingText.split("\n").length - 1;
350
+ // Remove \n characters from the selection.
351
+ matchOffset += linesCount;
352
+ }
353
+ codeEditor.setSelectionRange(matchOffset, matchOffset + matchLength);
354
+ }
355
+ codeEditor.focus();
356
+ });
357
+
358
+ // Create hash for all error blocks.
359
+ $('input:hidden[name="blocks[]"]').each(function() {
360
+ var blockId = parseInt(this.value);
361
+ var blockData = v03e.getBlockBoxData(blockId);
362
+ var errorTypeSelector = 'input:hidden[name="cjtoolbox[' + blockId + '][meta][v03e][errorType]' + '"]';
363
+ var hasError = (blockData.blockBox.find(errorTypeSelector).val() != undefined);
364
+ if (hasError) {
365
+ v03e.createBlockHash(blockData);
366
+ }
367
+ });
368
+ });
modules/v03e/v03e.php ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @version $Id ; v0.3e.php 16:33:02 07:02:2012 Ahmed Said ;
4
+ */
5
+
6
+ /**
7
+ * Provide error Blocks CODE detection and correction
8
+ * for the old version plugin.
9
+ *
10
+ * @author Ahmed Said
11
+ */
12
+ class CJTV03Error extends CJTModuleBase{
13
+
14
+ /**
15
+ * How many blocks with errors?
16
+ *
17
+ * @var integer
18
+ */
19
+ private $processedBlocks = 0;
20
+
21
+ /**
22
+ * Error types keys and display names.
23
+ *
24
+ * @var array
25
+ */
26
+ protected static $errorTypes = array(
27
+ 'error' => array(
28
+ 'displayName' => 'Error',
29
+ 'description' => 'error system is 100% positive that there is at least one error in the code, and would therefore need manual correcting (or Clean up).',
30
+ 'correctionRoutine' => 'v03e_fix_error',
31
+ 'detectionRoutine' => 'check_error',
32
+ ),
33
+ 'warning' => array(
34
+ 'displayName' => 'Warning',
35
+ 'description' => 'error system is not 100% positive if the detected error(s) is actually an error or not, and would therefore need help from you.',
36
+ 'correctionRoutine' => 'v03e_fix_warning',
37
+ 'detectionRoutine' => 'check_warning',
38
+ ),
39
+ );
40
+
41
+ /**
42
+ * Create CJTV03Error object.
43
+ *
44
+ * @param array Modul info struct.
45
+ * @return void
46
+ */
47
+ public function __construct($moduleInfo) {
48
+ parent::__construct($moduleInfo, true);
49
+ add_action('cjt_upgraded', array($this, 'upgrade'), 0, 9);
50
+ add_action('cjt_install', array($this, 'install'));
51
+ }
52
+
53
+ /**
54
+ * Override cssJSToolbox::admin_print_scripts method.
55
+ */
56
+ public function admin_print_scripts() {
57
+ // Enqueue cssJSToolbox scripts.
58
+ $this->cjToolbox->admin_print_scripts();
59
+ // Enquque additional scripts.
60
+ wp_enqueue_script(CJTOOLBOX_NAME . '-v03e-edc', $this->getJSFileURL('edc.js'));
61
+ $strings = array(
62
+ 'confirmCleanup' => __('After cleaning up this code block, you will not be able to scan the code again.') . "\n\n" .
63
+ __('Would you like to clean up the current code block?') . "\n\n" .
64
+ __('Nothing is saved until you click the "Save Changes" button.'),
65
+ 'CleanupScanIsOutdated' => __('The scan is outdated.') . "\n\n" .
66
+ __('This is may be a result of changing the block code.') . "\n\n" .
67
+ __('Please rescan the code and then click cleanUp.'),
68
+ 'confirmDismiss' => __('After dismissing this message you\'ll never be able to scan/clean this block again') . "\n\n" .
69
+ __('Are you sure?'),
70
+ 'codeCleaned' => __('Block code is now clean') . "\n\n" .
71
+ __('Nothing saved untill "Save all changes" button is clicked.'),
72
+ 'errorBoxTitle' => __('Current code block contains errors!!! Click here to show or hide the details'),
73
+ 'rescanOutdated' => __('Block code has been changed, scan is outdated!!!') . "\n\n" .
74
+ __('Would you like to rescan the code?'),
75
+ );
76
+ wp_localize_script(CJTOOLBOX_NAME . '-v03e-edc', 'CJTv03eLocalization', $strings);
77
+ }
78
+
79
+ /**
80
+ * Override cssJSToolbox::admin_print_scripts method.
81
+ */
82
+ public function admin_print_styles() {
83
+ // Enqueue cssJSToolbox scripts.
84
+ $this->cjToolbox->admin_print_styles();
85
+ // Enquque additional scripts.
86
+ wp_enqueue_style(CJTOOLBOX_NAME . '-v03e-edc', $this->getCSSFileURL('style.css'));
87
+ }
88
+
89
+ /**
90
+ * Callback for wp_ajax_cjtoolbox_v03e_checkCode hook.
91
+ */
92
+ public function ajaxCheckCode() {
93
+ $response = array('has' => false);
94
+ // Make sure this is a legal call.
95
+ $this->doAjax();
96
+ // Get post vars.
97
+ $code = filter_input(INPUT_POST, 'code', FILTER_UNSAFE_RAW);
98
+ $errorTypeName = $_POST['errorType'];
99
+ $blockId = $_POST['blockId'];
100
+ // Get error type object.
101
+ $detectedErrorType = self::$errorTypes[$errorTypeName];
102
+ $detectedErrorType['id'] = $errorTypeName;
103
+ // Prepare parameters for the view.
104
+ $checker = $detectedErrorType['detectionRoutine'];
105
+ $matches = $this->$checker($code);
106
+ // If its not array mean its clean.
107
+ if (is_array($matches)) {
108
+ $errorDetails['_list'] = $matches;
109
+ $response['has'] = true;
110
+ $response['message'] = $this->getView('scan-message', compact('detectedErrorType', 'errorDetails', 'blockId'));
111
+ }
112
+ // Output view.
113
+ header('Content-Type: text/plain');
114
+ die(json_encode($response));
115
+ }
116
+
117
+ /**
118
+ * Check if the code contains errors.
119
+ *
120
+ * @return array|null
121
+ */
122
+ public function check_error($code) {
123
+ $matchesList = array();
124
+ $expression = '/\\\\(\"|\\\')(?:\\\\\\\\\\1|.)*?\\\\\\1/';
125
+ if (preg_match_all($expression, $code, $matchesList, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
126
+ return $this->cleanDetectorMatches($matchesList);
127
+ }
128
+ return false;
129
+ }
130
+
131
+ /**
132
+ * Check if the code contains warnings.
133
+ *
134
+ * @param mixed $code
135
+ */
136
+ public function check_warning($code) {
137
+ $matchesList = array();
138
+ $expression = '/\\\\{2,}/';
139
+ if (preg_match_all($expression, $code, $matchesList, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
140
+ return $this->cleanDetectorMatches($matchesList);
141
+ }
142
+ return false;
143
+ }
144
+
145
+ /**
146
+ * Cleaned matches resturne from regular expression
147
+ * check to only contain the full match and the offset.
148
+ *
149
+ * @param array Regular expression matches list.
150
+ * @return array Cleaned matches.
151
+ */
152
+ protected function cleanDetectorMatches($matchesList) {
153
+ // Remove sub patterns matches.
154
+ foreach ($matchesList as $index => $match) {
155
+ $matchesList[$index] = array($match[0][1], $match[0][0]) ;
156
+ }
157
+ return $matchesList;
158
+ }
159
+
160
+ /**
161
+ * If all blocks are cleaned delete myself.
162
+ *
163
+ * Callback for cjt_manage_form_end action.
164
+ *
165
+ * @return void
166
+ */
167
+ public function deleteIfNoBlocks() {
168
+ // If all blocks are cleaned, delete myself.
169
+ if (!$this->processedBlocks) {
170
+ $this->install();
171
+ }
172
+ }
173
+
174
+ /**
175
+ * Check Ajax call nonce.
176
+ *
177
+ * @return void
178
+ */
179
+ protected function doAjax() {
180
+ check_ajax_referer('cjtoolbox-admin', 'security');
181
+ }
182
+
183
+ /**
184
+ * Get module instance.
185
+ *
186
+ * @see __construct for parameters info.
187
+ * @return CJTV03Error Module instance.
188
+ */
189
+ public static function getInstance($moduleInfo) {
190
+ return new CJTV03Error($moduleInfo);
191
+ }
192
+
193
+ /**
194
+ * Callback for cjt_install.
195
+ */
196
+ public function install() {
197
+ // Delete v03e module with new installation.
198
+ cssJSToolbox::$modulesEngine->delete($this->moduleInfo['id']);
199
+ // Don't extend cssJSToolbox class any more.
200
+ $this->leaveCJToolboxObject();
201
+ }
202
+
203
+ /**
204
+ * Output error message if the block contain errors.
205
+ *
206
+ * Callback for cjt_block_after_code hook.
207
+ *
208
+ * @return void
209
+ */
210
+ public function noteMessage($blockId, $block) {
211
+ // Work with only blocks those has the meta
212
+ if (isset($block['meta'][$this->moduleInfo['id']])) {
213
+ $errorDetails = $block['meta'][$this->moduleInfo['id']];
214
+ // If the blocks cleaned up the module meta is available
215
+ // but not the error-type.
216
+ if (isset($errorDetails['errorType']) && $errorDetails['errorType']) {
217
+ $detectedErrorType = self::$errorTypes[$errorDetails['errorType']];
218
+ $detectedErrorType['id'] = $errorDetails['errorType'];
219
+ $noteMessage = $this->getView('error-note', compact('blockId', 'block', 'errorDetails', 'detectedErrorType'));
220
+ $this->processedBlocks++;
221
+ echo $noteMessage;
222
+ }
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Recheck blocks data when data saved.
228
+ *
229
+ * Callback for cjt_data_saved hook.
230
+ *
231
+ * @return void
232
+ */
233
+ public function recheckBlocks($blocks) {
234
+ // Check blocks everytime blocks is updated.
235
+ $this->upgrade_checkBlocks($blocks, false);
236
+ }
237
+
238
+ /**
239
+ * Override cssJSToolbox::start_plugin method.
240
+ */
241
+ public function start_plugin() {
242
+ add_action('cjt_block_after_code', array($this, 'noteMessage'), 10, 2);
243
+ add_action('cjt_manage_form_end', array($this, 'deleteIfNoBlocks'));
244
+ add_action('wp_ajax_cjtoolbox_v03e_checkCode', array($this, 'ajaxCheckCode'));
245
+ add_action('cjt_data_saved', array($this, 'recheckBlocks'));
246
+ $this->cjToolbox->start_plugin();
247
+ }
248
+
249
+ /**
250
+ * Callback for cjt_upgrade hook.
251
+ */
252
+ public function upgrade() {
253
+ $this->upgrade_cleanUp();
254
+ $this->upgrade_checkBlocks();
255
+ }
256
+
257
+ /**
258
+ * When the plugin upgraded check if there are any blocks
259
+ * contain errors.
260
+ *
261
+ * @return void
262
+ */
263
+ protected function upgrade_checkBlocks($blocks = null) {
264
+ $destroyMySelf = true;
265
+ $moduleId = $this->moduleInfo['id'];
266
+ // NOTE: As a result of upgrading the Plugin
267
+ // This conditional should processed only once
268
+ // in Plugin life cycle.
269
+ $blocks = $blocks ? $blocks : $this->cjToolbox->getData();
270
+ // Copy for each block contain error.
271
+ $allErrorTypes = json_encode(array_keys(self::$errorTypes));
272
+ foreach ($blocks as $blockId => $block) {
273
+ foreach (self::$errorTypes as $errorKey => $errorTypeDetails) {
274
+ $blockMeta = (array) $block['meta'][$moduleId];
275
+ $dismissed = (isset($blockMeta["dismissed-{$errorKey}"]) && ($blockMeta["dismissed-{$errorKey}"]));
276
+ if (!$dismissed) {
277
+ $errorDetectorName = $errorTypeDetails['detectionRoutine'];
278
+ $matchesList = $this->$errorDetectorName($block['code']);
279
+ if (is_array($matchesList)) {
280
+ $blockErrorData = array(
281
+ 'allErrorTypes' => $allErrorTypes,
282
+ 'errorType' => $errorKey,
283
+ '_list' => $matchesList, // _ is hidden and isn't populated by the CJToolbox plugin.
284
+ );
285
+ $blocks[$blockId]['meta'][$moduleId] = array_merge($blockMeta, $blockErrorData);
286
+ $destroyMySelf = false; // Setting this more than one has no effect.
287
+ break; // WHen one error type if found don't check the others.
288
+ }
289
+ else { // Dismiss error when the block become clean.
290
+ unset($blocks[$blockId]['meta'][$moduleId]);
291
+ }
292
+ } // !$dismissed
293
+ }
294
+ }
295
+ if ($destroyMySelf) {
296
+ // Same case like new installation.
297
+ // Don't run anymore.
298
+ $this->install();
299
+ }
300
+ else {
301
+ // Save blocks meta data.
302
+ $this->cjToolbox->saveData($blocks);
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Cleanup blocks and template code from the extra slashes.
308
+ *
309
+ * @return void
310
+ */
311
+ protected function upgrade_cleanUp() {
312
+ global $wpdb;
313
+ $templateTable = "{$wpdb->prefix}cjtoolbox_cjdata";
314
+ /// Clean up blocks code.
315
+ $blocks = (array) get_option(cssJSToolbox::BLOCKS_OPTION_NAME);
316
+ foreach ($blocks as $id => $block) {
317
+ // Remove extra slahses introduced from the first version
318
+ // as a result of the magic quotes.
319
+ $blocks[$id]['code'] = stripcslashes($block['code']);
320
+ }
321
+ // Save clean blocks.
322
+ update_option(cssJSToolbox::BLOCKS_OPTION_NAME, $blocks);
323
+ /// Clean up code templates.
324
+ $query = "SELECT type, id, code FROM {$templateTable}";
325
+ $templates = $wpdb->get_results($query, ARRAY_A);
326
+ foreach ($templates as $template) {
327
+ $cleanCode = stripcslashes($template['code']);
328
+ // Leave only id and type as update keys.
329
+ unset($template['code']);
330
+ $wpdb->update($templateTable, array('code' => $cleanCode), $template);
331
+ }
332
+ }
333
+
334
+ } // End class.
335
+
336
+ // Put the module in action.
337
+ return CJTV03Error::getInstance($module);
modules/v03e/views/error-note.html.tmpl ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="v03e-error-note-block-<?php echo $blockId ?>" class="v03e-block-message">
2
+ <div class="notification-bar notify-<?php echo $errorDetails['errorType'] ?>">
3
+ <p><?php _e('Current code block contains errors!!! Click here to show or hide the details') ?></p>
4
+ </div>
5
+ <div class="message-area">
6
+ <div class="help">
7
+ <p>
8
+ <?php _e('You have upgraded from an older version, and unfortunately the previous version introduced an error, which needs correcting.') ?>
9
+ <?php _e('Inspect your code blocks and you may notice extra back slash characters occurring before quotes, double quotes and other back slashes.') ?>
10
+ <?php _e('Due to a bug, these \'additional\' back slash characters were added when code was inserted from the CSS or JS Template drop-down boxes.') ?>
11
+ <?php _e('In this latest version, we have created an error detection and correction system to help you to fix these errors.') ?>
12
+ <?php _e('Please note that the error detection and correction system can not be 100% certain if the detected error is actually an error or not.') ?>
13
+ <?php _e('Therefore, you would need to assist this error system by confirming whether the back slash character should be there or not.') ?>
14
+ <?php _e('Consider backing up your code blocks by clicking the Backup link in the top right corner beforehand, then you can restore your code blocks.') ?>
15
+ <?php _e('Clicking \'Clean up\' will clean extra back slash errors and you can see this happen in the editor window. For a video on how this works, please click:') ?> <a href="http://wipeoutmedia.com/wordpress-plugins/cjt-bug-fix-upgrading-to-v0-8" target="_blank"><?php _e('Help Video') ?></a>
16
+ <h4><?php _e('This error system for detecting and correcting code blocks supports the following error types:') ?></h4>
17
+ </p>
18
+ <ul class="v0e3-error-types-list">
19
+ <?php
20
+ $errorTypes = json_decode($errorDetails['allErrorTypes']);
21
+ foreach ($errorTypes as $errorKey) :
22
+ $errorType = CJTV03Error::$errorTypes[$errorKey];
23
+ ?>
24
+ <li><p class="txt-<?php echo $errorKey ?>"><?php _e($errorType['displayName']) ?>: <?php _e($errorType['description']) ?></p></li>
25
+ <?php
26
+ endforeach;
27
+ ?>
28
+ </ul>
29
+ </div>
30
+ <?php require 'scan-message.html.tmpl' ?>
31
+ <div class="v03e-loader" id="v03e-block-loader-<?php echo $blockId ?>">
32
+ <img src="<?php echo CJTOOLBOX_MEDIA_URL . '/ajax-loader.gif' ?>" />
33
+ </div>
34
+ <div class="commands">
35
+ <a href="javascript:void('#');" onclick="v03e.nextError(<?php echo $blockId ?>, true)"><?php _e('Dismiss') ?></a> |
36
+ <a href="javascript:void('#');" onclick="v03e.rescan(<?php echo $blockId ?>)"><?php _e('Re-scan') ?></a> |
37
+ <a href="javascript:void('#');" onclick="v03e.cleanUpBlock(<?php echo $blockId ?>)"><?php _e('Clean up') ?></a>
38
+ </div>
39
+ </div>
40
+ </div>
modules/v03e/views/scan-message.html.tmpl ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="error-message">
2
+ <p><?php _e('Detected error') ?>: <span class="txt-<?php echo $detectedErrorType['id'] ?>"><?php _e($detectedErrorType['displayName']) ?></span></p>
3
+ <div class="error-list-container">
4
+ <ul class="error-list blockID-<?php echo $blockId ?>">
5
+ <?php
6
+ $list = $errorDetails['_list'];
7
+ foreach($list as $index => $errorMatch) :
8
+ ?>
9
+ <li>
10
+ <input type="hidden" name="cjtoolbox[<?php echo $blockId ?>][meta][<?php echo $this->moduleInfo['id'] ?>][_list][<?php echo $index ?>][0]" value="<?php echo $errorMatch[0] ?>" />
11
+ <input type="checkbox" name="cjtoolbox[<?php echo $blockId ?>][meta][<?php echo $this->moduleInfo['id'] ?>][_list][<?php echo $index ?>][1]" value="<?php echo htmlspecialchars($errorMatch[1]) ?>" checked="checked" /> <?php echo htmlspecialchars($errorMatch[1]) ?>
12
+ </li>
13
+ <?php
14
+ endforeach;
15
+ ?>
16
+ <input type="hidden" id="cjtoolbox[<?php echo $blockId ?>][meta][<?php echo $this->moduleInfo['id'] ?>][_list_json]" value="<?php echo htmlspecialchars(json_encode($list)) ?>" />
17
+ <input type="hidden" id="cjtoolbox[<?php echo $blockId ?>][meta][<?php echo $this->moduleInfo['id'] ?>][_code_hash]" value="#" />
18
+ </ul>
19
+ <p class="matches-note"><?php _e('For the location of each match, click on the item.') ?></p>
20
+ </div>
21
+ </div>
premium-update-check.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @version $Id ; premium-update-check.php 080 00:00:00 28-01-2012 Ahmed Said $
4
+ */
5
+
6
+ /**
7
+ * Avoid direct calls to this file where wp core files not present
8
+ */
9
+ if (!function_exists ('add_action')) {
10
+ header('Status: 403 Forbidden');
11
+ header('HTTP/1.1 403 Forbidden');
12
+ exit();
13
+ }
14
+
15
+ /**
16
+ * CjToolbox premium version checker.
17
+ *
18
+ * @author Ahmed Said
19
+ */
20
+ abstract class CJTPremiumUpdate {
21
+
22
+ /**
23
+ * Run once everyday at the time the Plugin activated.
24
+ * Callback for wp_schedule_event.
25
+ */
26
+ public static function check() {
27
+ // Ask the server for updates.
28
+ $response = wp_remote_get(cssJSToolbox::CHECK_UPDATE_URL);
29
+ // If check success, store the response.
30
+ if (is_array($response)) { // response = WP_Error on failure.
31
+ // We need only response array.
32
+ $response = @unserialize($response['body']);
33
+ // Make sure that we got array from the server.
34
+ if (is_array($response['response'])) {
35
+ $response = $response['response'];
36
+ $currentVersion = is_array(cssJSToolbox::$premiumUpgradeTransient) ? cssJSToolbox::$premiumUpgradeTransient['version'] : '';
37
+ $newVersion = $response['version'];
38
+ // Upload and update image URL only if current transient version
39
+ // is different from the new version.
40
+ if ($currentVersion != $newVersion) {
41
+ // Get image from URL.
42
+ $image = wp_remote_get($response['imageURL']);
43
+ // $image = WP_Error on failure.
44
+ if (is_array($image)) {
45
+ $imagesUploadPath = CJTOOLBOX_PATH . '/public/media/' . cssJSToolbox::IMAGES_UPLOAD_DIR;
46
+ $imageStream = $image['body'];
47
+ $imageName = basename($response['imageURL']);
48
+ $imageFile = "{$imagesUploadPath}/{$imageName}";
49
+ $localImageLength = @file_put_contents($imageFile, $imageStream);
50
+ // If file is created change the URL of the image to the local image.
51
+ if ($localImageLength == strlen($imageStream)) {
52
+ $response['imageURL'] = CJTOOLBOX_MEDIA_URL . '/' . cssJSToolbox::IMAGES_UPLOAD_DIR . "/{$imageName}";
53
+ // Store the response/transient with the new ImageURL, make sense!
54
+ }
55
+ }
56
+ }
57
+ // Update current transient.
58
+ set_site_transient('cjt_premium_upgrade', $response);
59
+ cssJSToolbox::$premiumUpgradeTransient = $response;
60
+ }
61
+ }
62
+ }
63
+
64
+ } // End class.
{media → public/css}/admin.css RENAMED
@@ -1,4 +1,4 @@
1
- /** CSS & Javascript Toolkit - Admin CSS **/
2
  .wrap { position:relative; }
3
  .wrap h2 { float:left; }
4
  #wpcontent { min-width:1040px; }
@@ -7,38 +7,48 @@
7
  #cjtoolbox_donate input { position:absolute; right:0; top:0; }
8
 
9
  #cjtoolbox_form { clear:both; }
10
- .cjcodeblock { margin-right:350px; min-width:660px; }
11
- .cjpageblock { width:320px; position:absolute; right:12px; }
12
  .pagelist { padding:10px; height:172px; overflow:auto; background:#fff; border:1px solid #ccc; }
13
  .pagelist li { line-height:19px; word-wrap:break-word; margin:0; padding:0; }
14
  .pagelist ul { margin-left:18px; }
15
  .cssblock, .jsblock { width:50%; }
16
  .cssblock { float:left; }
17
  .jsblock { float:right; }
18
- .datablock textarea { width:100%; height:242px; }
19
- .deleteblock a.button-secondary { padding:5px 10px; margin:10px 0 5px; float:right; }
20
- .linklist textarea { width:290px; font-size:11px; height:190px; }
 
21
 
22
  .cjtitle { float:left; width:245px; }
23
  .cssblock select { width:150px; }
24
  .jsblock select { width:155px; }
25
- .cjbutton { width:85px; height:20px; float:left; }
26
- .cjbutton a { height:20px; width:20px; text-indent:-999em; margin:5px 5px 0 0; display:block; float:left; }
27
- .cjexample { clear:both; float:left; padding:5px 0 0; }
28
- a.add_code { background:url(icons/add_code.png) no-repeat; }
29
- a.delete_code { background:url(icons/delete_code.png) no-repeat; }
30
- a.insert_code { background:url(icons/insert_code.png) no-repeat; }
31
- a.l_ext { background:url(icons/external_link.gif) no-repeat; width:13px; height:11px; display:inline-block; }
 
 
 
 
 
 
32
 
33
  #cjtoolbox-addblock { float:left; padding:5px 10px; }
34
 
35
  #cjtoolbox-tips { padding:20px; }
36
  #cjtoolbox-tips ul li { list-style-type:square; }
37
 
 
 
 
38
 
39
  .cj-save-popup { position:absolute; -moz-border-radius:12px; -webkit-border-radius:12px; border-radius:12px; background:rgba(0, 0, 0, 0.4); color:#fff; font-size:24px; text-align:center; display:none; z-index:99; }
40
- #cj-save-save { background:url(accept.png) 20px 50% no-repeat; padding:30px 30px 30px 70px; }
41
- #cj-save-reset { background:url(warning.png) 20px 50% no-repeat; padding:30px 30px 30px 70px; }
42
 
43
  #cj-ajax-load { position:absolute; background:rgba(255, 255, 255, 0.8); text-align:center; display:none; padding:50px; z-index:999; width:100%; height:100%; }
44
  #cj-ajax-load img { position:absolute; }
@@ -47,6 +57,9 @@ a.l_ext { background:url(icons/external_link.gif) no-repeat; width:13px; height:
47
  .hide { display:none }
48
  .ajax-loading-img-top { margin: 8px 4px 0; float:left }
49
 
 
 
 
50
 
51
  /*
52
  * jQuery UI Tabs 1.8.16
@@ -65,5 +78,5 @@ a.l_ext { background:url(icons/external_link.gif) no-repeat; width:13px; height:
65
  .ui-tabs .ui-tabs-nav li.ui-tabs-selected { margin-bottom: 0; padding-bottom: 1px; }
66
  .ui-tabs .ui-tabs-nav li.ui-tabs-selected a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-state-processing a { cursor: text; background:#E9E9E9; border-color:#CCCCCC #CCCCCC #E9E9E9; color:#333333; }
67
  .ui-tabs .ui-tabs-nav li a, .ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a { cursor: pointer; } /* first selector in group seems obsolete, but required to overcome bug in Opera applying cursor: text overall if defined elsewhere... */
68
- .ui-tabs .ui-tabs-panel { display: block; padding: 5px 10px; background: #EFEFEF; border-color:#CCCCCC; border-style:solid;border-width:1px;border-collapse:separate;-moz-border-radius:3px 3px 0 0;-webkit-border-top-right-radius:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-right-radius:3px;-khtml-border-top-left-radius:3px;border-top-right-radius:3px;border-top-left-radius:3px; clear:both; height:228px; }
69
  .ui-tabs .ui-tabs-hide { display: none !important; }
1
+ /** CSS &amp; Javascript Toolkit - Admin CSS **/
2
  .wrap { position:relative; }
3
  .wrap h2 { float:left; }
4
  #wpcontent { min-width:1040px; }
7
  #cjtoolbox_donate input { position:absolute; right:0; top:0; }
8
 
9
  #cjtoolbox_form { clear:both; }
10
+ .cjcodeblock { margin-right:350px; min-width:780px; }
11
+ .cjpageblock { width:272px; height: 298px; position:absolute; right:12px; }
12
  .pagelist { padding:10px; height:172px; overflow:auto; background:#fff; border:1px solid #ccc; }
13
  .pagelist li { line-height:19px; word-wrap:break-word; margin:0; padding:0; }
14
  .pagelist ul { margin-left:18px; }
15
  .cssblock, .jsblock { width:50%; }
16
  .cssblock { float:left; }
17
  .jsblock { float:right; }
18
+ .datablock {clear:both;} /* IE8 */
19
+ .datablock textarea { width:99%; height:242px; }
20
+ .deleteblock a.button-secondary { padding:5px 10px; margin:10px 5px 5px; float:right; }
21
+ .linklist textarea { width:245px; font-size:11px; height:190px; }
22
 
23
  .cjtitle { float:left; width:245px; }
24
  .cssblock select { width:150px; }
25
  .jsblock select { width:155px; }
26
+ .cjbutton { width:116px; height:24px; float:left; }
27
+ .cjbutton a { height:24px; width:24px; text-indent:-999em; display:block; float:left; }
28
+ .cjexample { clear:left; float:left; padding:5px 0 0; }
29
+ .upgradeLink { margin-top: -8px; float:left; margin-left: 60px; padding:5px 0 0;}
30
+ .upgradeLink img{ position: relative; top: 8px; }
31
+ .embedded-scripts-link{ margin-top: 16px; }
32
+
33
+ a.add_code { background:url(../media/icons/add_code.png) no-repeat; }
34
+ a.edit_code { background:url(../media/icons/edit_code.png) no-repeat; }
35
+ a.delete_code { background:url(../media/icons/delete_code.png) no-repeat; }
36
+ a.insert_code { background:url(../media/icons/insert_code.png) no-repeat; }
37
+ a.l_ext { position: relative; top: 3px; background:url(../media/icons/external_link.png) no-repeat; width:18px; height:13px; display:inline-block; }
38
+ a.save_changes_button, a:hover.save_changes_button, a:visited.save_changes_button{color: #21759B;}
39
 
40
  #cjtoolbox-addblock { float:left; padding:5px 10px; }
41
 
42
  #cjtoolbox-tips { padding:20px; }
43
  #cjtoolbox-tips ul li { list-style-type:square; }
44
 
45
+ .field-title{ width: 100px; display: inline-block; }
46
+ #new_code {width: 324px; height: 248px; }
47
+ .popup-note{ text-align:justify;background-color:snow;padding: 3px 3px 3px 3px; }
48
 
49
  .cj-save-popup { position:absolute; -moz-border-radius:12px; -webkit-border-radius:12px; border-radius:12px; background:rgba(0, 0, 0, 0.4); color:#fff; font-size:24px; text-align:center; display:none; z-index:99; }
50
+ #cj-save-save { background:url(../media/accept.png) 20px 50% no-repeat; padding:30px 30px 30px 70px; }
51
+ #cj-save-reset { background:url(../media/warning.png) 20px 50% no-repeat; padding:30px 30px 30px 70px; }
52
 
53
  #cj-ajax-load { position:absolute; background:rgba(255, 255, 255, 0.8); text-align:center; display:none; padding:50px; z-index:999; width:100%; height:100%; }
54
  #cj-ajax-load img { position:absolute; }
57
  .hide { display:none }
58
  .ajax-loading-img-top { margin: 8px 4px 0; float:left }
59
 
60
+ .cjt-block-scripts ul{ list-style: none; margin: 0px; padding: 5px 5px 5px 5px; height: 450px; overflow: auto; }
61
+ .cjt-block-scripts ul li{ display: inline-block; background: none; width: 200px; }
62
+ .marked-text{ color: #bf6b19; }
63
 
64
  /*
65
  * jQuery UI Tabs 1.8.16
78
  .ui-tabs .ui-tabs-nav li.ui-tabs-selected { margin-bottom: 0; padding-bottom: 1px; }
79
  .ui-tabs .ui-tabs-nav li.ui-tabs-selected a, .ui-tabs .ui-tabs-nav li.ui-state-disabled a, .ui-tabs .ui-tabs-nav li.ui-state-processing a { cursor: text; background:#E9E9E9; border-color:#CCCCCC #CCCCCC #E9E9E9; color:#333333; }
80
  .ui-tabs .ui-tabs-nav li a, .ui-tabs.ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-selected a { cursor: pointer; } /* first selector in group seems obsolete, but required to overcome bug in Opera applying cursor: text overall if defined elsewhere... */
81
+ .ui-tabs .ui-tabs-panel { display: block; padding: 5px 10px; background: #EFEFEF; border-color:#CCCCCC; border-style:solid;border-width:1px;border-collapse:separate;-moz-border-radius:3px 3px 0 0;-webkit-border-top-right-radius:3px;-webkit-border-top-left-radius:3px;-khtml-border-top-right-radius:3px;-khtml-border-top-left-radius:3px;border-top-right-radius:3px;border-top-left-radius:3px; clear:both }
82
  .ui-tabs .ui-tabs-hide { display: none !important; }
public/js/admin.js ADDED
@@ -0,0 +1,426 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ var cjt_data_saved_callbacks = [];
3
+
4
+ jQuery(document).ready(function($) {
5
+ $('form#cjtoolbox_form').submit(function() {
6
+ var data = $(this).serialize();
7
+ var manage_form = this;
8
+ $('#cj-ajax-load').fadeIn();
9
+ $.post(ajaxurl, data, function(response) {
10
+ var success = $('#cj-popup-save');
11
+ var loading = $('#cj-ajax-load');
12
+ $.each(cjt_data_saved_callbacks, function(index, callback) {
13
+ var callbackExp = callback[0] + '.' + callback[1] + ';';
14
+ var callbackMethod = eval(callbackExp);
15
+ callbackMethod();
16
+ });
17
+ loading.fadeOut();
18
+ success.fadeIn();
19
+ window.setTimeout(function(){
20
+ success.fadeOut();
21
+ }, 3000);
22
+ var blocks = manage_form.elements['blocks[]'];
23
+ if (blocks.length == undefined) {
24
+ blocks = [blocks];
25
+ }
26
+ // If the blocks count > 1, make sure that all the blocks delete buttons are visible.
27
+ if (response.availableCount > 1) {
28
+ $.each(blocks, function(index, block){
29
+ var blockId = parseInt(block.value) + 1;
30
+ var selector = '#cjtoolbox-' + blockId;
31
+ var deleteButton = $(selector + ' a.delete_block_button');
32
+ deleteButton.show();
33
+ });
34
+ }
35
+ // Mark which blocks is synchronized(saved on server).
36
+ $.each(blocks, function(index, block) {
37
+ var blockNodeId = parseInt(block.value) + 1;
38
+ var selector = '#cjtoolbox-' + blockNodeId + ' input[name="sync"]';
39
+ var syncField = $(selector);
40
+ // If the block is saved set sync = true, else set sync = false.
41
+ if (response.savedIds.indexOf(parseInt(block.value)) == -1) {
42
+ syncField.val(0);
43
+ }
44
+ else {
45
+ syncField.val(1);
46
+ }
47
+ });
48
+ // Refresh content hash list.
49
+ contentHash.generate();
50
+ }, 'json');
51
+ return false;
52
+ });
53
+
54
+ //Update Message popup
55
+ jQuery.fn.center = function () {
56
+ this.animate({"top":( jQuery(window).height() - this.height() - 200 ) / 2 + jQuery(window).scrollTop() + "px"}, 50);
57
+ this.animate({"left":( jQuery(window).width() - this.width() - 200 ) / 2 + "px"}, 50);
58
+ return this;
59
+ }
60
+
61
+ // Update loading
62
+ jQuery.fn.loadingcenter = function () {
63
+ this.animate({"top":( jQuery(window).height() - this.height() - 60 ) / 2 + jQuery(window).scrollTop() + "px"}, 50);
64
+ this.animate({"left":( jQuery(window).width() - this.width() - 60 ) / 2 + "px"}, 50);
65
+ return this;
66
+ }
67
+
68
+
69
+ jQuery('#cj-popup-save').center();
70
+ jQuery('#cj-popup-reset').center();
71
+ jQuery('#cj-ajax-load img').loadingcenter();
72
+ jQuery(window).scroll(function() {
73
+ jQuery('#cj-popup-save').center();
74
+ jQuery('#cj-popup-reset').center();
75
+ jQuery('#cj-ajax-load img').loadingcenter();
76
+ });
77
+
78
+ jQuery('#cjtoolbox-addblock').click(function(e) {
79
+ var count = jQuery('#cjblock-count').val();
80
+ var id = parseInt(count);
81
+ var security = jQuery('#cjsecurity').val();
82
+ var data = {
83
+ action : 'cjtoolbox_add_block',
84
+ count : count++,
85
+ security : security
86
+ };
87
+ jQuery('#cj-ajax-load').fadeIn();
88
+ jQuery.post(ajaxurl, data, function(response) {
89
+ var loading = jQuery('#cj-ajax-load');
90
+ loading.fadeOut();
91
+ if(response == '' || response == 0) {
92
+ alert(localization.addBlockFailed);
93
+ } else {
94
+ var newId = 'cjtoolbox-' + count;
95
+ jQuery('#normal-sortables > div').removeClass('postbox'); // For postboxes.add_postbox_toggles to work.
96
+ jQuery('#normal-sortables').append(response);
97
+ jQuery(".meta-box-sortables").sortable('refresh');
98
+ jQuery('#cjblock-count').val(count);
99
+ jQuery('#' + newId + ' a.edit_block_button').click();
100
+ postboxes.add_postbox_toggles('settings_page_cjtoolbox'); // Add to toggling objects.
101
+ jQuery('#normal-sortables > div').addClass('postbox'); // Reset blocks.
102
+ }
103
+ });
104
+ return false; // For link to behave inactive
105
+ });
106
+
107
+ });
108
+
109
+ // Save all changes.
110
+ function block_saveAllChanges() {
111
+ jQuery('form#cjtoolbox_form').submit();
112
+ }
113
+
114
+ function edit_code(securityToken, blockId, dialogTitle, type, width, height) {
115
+ // Get template id based on the type.
116
+ var listId = '#cjtoolbox-' + type + '-' + blockId;
117
+ var list = jQuery(listId).get(0);
118
+ var id = list.options[list.selectedIndex].value;
119
+ // Query string.
120
+ var data = {
121
+ action : 'cjtoolbox_form',
122
+ type : type,
123
+ id : id,
124
+ width : width,
125
+ height : height,
126
+ security: securityToken
127
+ };
128
+ var url = ajaxurl + '?' + jQuery.param(data);
129
+ tb_show(dialogTitle, url);
130
+ }
131
+
132
+ function insert_code(type, id) {
133
+ var cid = jQuery('#cjtoolbox-'+type+'-'+id+ ' option:selected').val();
134
+ var security = jQuery('#cjsecurity').val();
135
+ var data = {
136
+ action : 'cjtoolbox_get_code',
137
+ type : type,
138
+ id : cid,
139
+ security : security
140
+ };
141
+ jQuery('#cj-ajax-load').fadeIn();
142
+ jQuery.post(ajaxurl, data, function(response) {
143
+ var loading = jQuery('#cj-ajax-load');
144
+ loading.fadeOut();
145
+ if(response == '' || response == 0) {
146
+ alert(localization.unableToReadCode.replace('{type}', type));
147
+ } else {
148
+ jQuery('#cjcode-'+id).insertAtCaret(response);
149
+ }
150
+ });
151
+ return false; // For link to behave inactive
152
+ }
153
+
154
+ function delete_code(type, id) {
155
+ var sure = confirm(localization.confirmDeleteTemplate);
156
+ if(!sure) return false;
157
+
158
+ var cid = jQuery('#cjtoolbox-'+type+'-'+id+ ' option:selected').val();
159
+ var security = jQuery('#cjsecurity').val();
160
+ var data = {
161
+ action : 'cjtoolbox_delete_code',
162
+ type : type,
163
+ id : cid,
164
+ security : security
165
+ };
166
+ jQuery('#cj-ajax-load').fadeIn();
167
+ jQuery.post(ajaxurl, data, function(response) {
168
+ var loading = jQuery('#cj-ajax-load');
169
+ loading.fadeOut();
170
+ if(response == '' || response == 0) {
171
+ alert(localization.cantDeleteTemplate.replace('{type}', type));
172
+ } else {
173
+ alert(localization.templateDeleted.replace('{type}', type));
174
+ jQuery('.cjtoolbox-'+type).each(function() {
175
+ jQuery(this).find('option[value='+cid+ ']').remove();
176
+ });
177
+ }
178
+ });
179
+ return false; // For link to behave inactive
180
+ }
181
+
182
+ function delete_block(id, isInternal) {
183
+ var manage_form = jQuery('#cjtoolbox_form').get(0);
184
+ var block = jQuery('#cjtoolbox-' + id);
185
+ var block_name = manage_form.elements['cjtoolbox[' + (id - 1) + '][block_name]'].value;
186
+ var confirmMessage = localization.confirmDeleteBlock.replace('{block_name}', block_name);
187
+ if ((isInternal != undefined) || confirm(confirmMessage)) {
188
+ // Remove block box.
189
+ block.remove();
190
+ // Disallow deleting the last block.
191
+ var blocks = manage_form.elements['blocks[]'];
192
+ // If the length is undefined then the returned object is HTMLInput not a Nodelist.
193
+ if (blocks.length == undefined) {
194
+ var blockBoxId = (parseInt(blocks.value) + 1);
195
+ var deleteButton = jQuery('#cjtoolbox-' + blockBoxId + ' a.delete_block_button');
196
+ deleteButton.hide();
197
+ }
198
+ // Delete only when the block is saved in the server
199
+ // Isinternal = true mean the block is added and deleted
200
+ // without server knowledge. So ignore it.
201
+ if (!isInternal) {
202
+ // Delete block from content hashing object.
203
+ contentHash.deleteBlock(id - 1);
204
+ }
205
+ }
206
+ return false; // For link to behave inactive
207
+ }
208
+
209
+ jQuery(document).ready(function($) {
210
+ $('#cjtoolbox_newcode').live('submit',
211
+ function (event) {
212
+ event.preventDefault();
213
+ var title = $('#cjtoolbox_newcode #new_title').val();
214
+ var code = $('#cjtoolbox_newcode #new_code').val();
215
+ var type = $('#cjtoolbox_newcode #new_type').val();
216
+ var id = $('#cjtoolbox_newcode #new_id').val();
217
+ var content_hash = $('#cjtoolbox_newcode #content_hash').val();
218
+ var security = $('#cjtoolbox_newcode #new_security').val();
219
+ if(!title) {
220
+ alert(localization.titleFieldMissing);
221
+ }
222
+ else if(!code) {
223
+ alert(localization.codeFieldMissing);
224
+ }
225
+ else {
226
+ // If there is no change made with the template data get out.
227
+ var new_content_hash = getCodeTemplateContentHash();
228
+ if (new_content_hash == content_hash) {
229
+ var exit = confirm(localization.noChangeMadeCouldNotSaveTemplate);
230
+ if (exit) {
231
+ tb_remove();
232
+ }
233
+ return;
234
+ }
235
+ var data = {
236
+ action : 'cjtoolbox_save_newcode',
237
+ type : type,
238
+ title : title,
239
+ code : code,
240
+ id : id,
241
+ security : security
242
+ };
243
+ jQuery('#cjtoolbox_popup .ajax-loading-img').fadeIn();
244
+ jQuery.post(ajaxurl, data, function(result) {
245
+ var loading = jQuery('#cjtoolbox_popup .ajax-loading-img');
246
+ loading.fadeOut();
247
+ if (!result.responseCode) {
248
+ alert(localization.couldNotSaveTemplate);
249
+ return;
250
+ }
251
+ if (result.operation == 'update') {
252
+ jQuery('select.cjtoolbox-' + type + ' > option[value=' + id + ']').each(function() {
253
+ jQuery(this).text(title);
254
+ });
255
+ }
256
+ else if (result.operation == 'insert') {
257
+ jQuery('.cjtoolbox-' + type).each(function() {
258
+ jQuery(this).append('<option value="' + result.id + '">' + title + '</option>');
259
+ });
260
+ }
261
+ alert(localization.templateSavedSuccessful.replace('{title}', title).replace('{type}', type.toUpperCase()));
262
+ tb_remove();
263
+ }, 'json');
264
+ return false;
265
+ }
266
+ });
267
+ });
268
+
269
+ jQuery(document).ready(function($){
270
+ $('#cjtoolbox_block_name').live('submit', function(event){
271
+ event.preventDefault();
272
+ // Get forms.
273
+ var popup_form = this;
274
+ var manage_form = $('#cjtoolbox_form').get(0);
275
+ var block_id = parseInt(popup_form.block_id.value); // Index based-zero id.
276
+ var selectBlockId = block_id + 1; // Index based-one id.
277
+ var newBlockMarker = jQuery('#cjtoolbox-' + selectBlockId + ' input[name="is_new"]');
278
+ // Block name cannot be null
279
+ if (!popup_form.block_name.value) {
280
+ alert(localization.blockNameMissing);
281
+ return;
282
+ }
283
+ else {
284
+ // Check if the name used by another block.
285
+ var blocks = manage_form.elements['blocks[]'];
286
+ var blkName = '';
287
+ var isUnique = true;
288
+ if (blocks.length == undefined) {
289
+ blocks = [blocks];
290
+ }
291
+ $.each(blocks, function(index, id) {
292
+ blkName = manage_form.elements['cjtoolbox[' + id.value + '][block_name]'].value;
293
+ if ((blkName == popup_form.block_name.value) && (id.value != block_id)) {
294
+ isUnique = false;
295
+ return;
296
+ }
297
+ });
298
+ if (!isUnique) {
299
+ alert(localization.blockNameIsInUse);
300
+ return;
301
+ }
302
+ }
303
+ // Update block name field.
304
+ manage_form.elements['cjtoolbox[' + block_id + '][block_name]'].value = popup_form.block_name.value;
305
+ // Also update block display name.
306
+ var block_display_selector = '#cjtoolbox-' + selectBlockId + ' h3.hndle > span'
307
+ var newTitle = 'CSS & JavaScript Block: ' + popup_form.block_name.value;
308
+ $(block_display_selector).text(newTitle);
309
+ // If adding new block add to content hash object.
310
+ if (parseInt(newBlockMarker.val())) {
311
+ contentHash.add(block_id);
312
+ }
313
+ // Mark the block as "not new".
314
+ newBlockMarker.val(0);
315
+ tb_remove();
316
+ });
317
+ });
318
+
319
+ function editBlockNameForm(dialogTitle, securityNonce, blockId, width, height) {
320
+ var blockSerialId = blockId + 1;
321
+ var manage_form = jQuery('#cjtoolbox_form').get(0);
322
+ var isNewBlock = jQuery('#cjtoolbox-' + blockSerialId + ' input[name="is_new"]').val();
323
+ var data = {
324
+ security : securityNonce,
325
+ action : 'cjtoolbox_request_template',
326
+ name : 'blockname',
327
+ block_name : manage_form.elements['cjtoolbox[' + blockId + '][block_name]'].value,
328
+ block_id : blockId,
329
+ width : width,
330
+ height : height,
331
+ isNew : isNewBlock
332
+ };
333
+ var url = ajaxurl + '?' + jQuery.param(data);
334
+ tb_show(dialogTitle, url);
335
+ }
336
+
337
+ function closeBlockNameForm(blockId, isNew){
338
+ if (isNew) {
339
+ delete_block(blockId + 1, true);
340
+ }
341
+ tb_remove();
342
+ }
343
+
344
+ function scriptsForm(dialogTitle, securityNonce, blockId, width, height) {
345
+ var blockSerialId = blockId + 1;
346
+ var manage_form = jQuery('#cjtoolbox_form').get(0);
347
+ var data = {
348
+ security : securityNonce,
349
+ action : 'cjtoolbox_request_template',
350
+ name : 'scripts',
351
+ selections : manage_form.elements['cjtoolbox[' + blockId + '][scripts]'].value,
352
+ block_id : blockId,
353
+ width : width,
354
+ height : height
355
+ };
356
+ var url = ajaxurl + '?' + jQuery.param(data);
357
+ tb_show(dialogTitle, url);
358
+ }
359
+
360
+ // Save embedded scripts list.
361
+ (function($) {
362
+ $('form#cjtoolbox_embedded_scripts').live('submit', function(event) {
363
+ event.preventDefault();
364
+ var manage_form = jQuery('#cjtoolbox_form').get(0);
365
+ var blockId = this.block_id.value;
366
+ var scripts = [];
367
+ $.each(this.elements['cjt-scripts[]'], function(index, scriptNode) {
368
+ if ($(scriptNode).prop('checked')) {
369
+ scripts.push(scriptNode.value);
370
+ }
371
+ });
372
+ scripts = scripts.join(',');
373
+ manage_form.elements['cjtoolbox[' + blockId + '][scripts]'].value = scripts;
374
+ tb_remove();
375
+ });
376
+ })(jQuery);
377
+
378
+ function getCodeTemplateContentHash(){
379
+ var title = jQuery('#cjtoolbox_newcode #new_title').val();
380
+ var code = jQuery('#cjtoolbox_newcode #new_code').val();
381
+ return hex_md5(title + code);
382
+ }
383
+
384
+ jQuery.fn.extend({
385
+ insertAtCaret: function(myValue){
386
+ return this.each(function(i) {
387
+ if (document.selection) {
388
+ this.focus();
389
+ sel = document.selection.createRange();
390
+ sel.text = myValue;
391
+ this.focus();
392
+ }
393
+ else if (this.selectionStart || this.selectionStart == '0') {
394
+ var startPos = this.selectionStart;
395
+ var endPos = this.selectionEnd;
396
+ var scrollTop = this.scrollTop;
397
+ this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
398
+ this.focus();
399
+ this.selectionStart = startPos + myValue.length;
400
+ this.selectionEnd = startPos + myValue.length;
401
+ this.scrollTop = scrollTop;
402
+ } else {
403
+ this.value += myValue;
404
+ this.focus();
405
+ }
406
+ })
407
+ }
408
+ });
409
+
410
+ //
411
+ function embedded_block_scripts(blockId) {
412
+
413
+ }
414
+
415
+ /**
416
+ * Notify saving changes.
417
+ */
418
+ (function($){
419
+ $(document).ready(function() {
420
+ $(window).bind('beforeunload', function() {
421
+ if (contentHash.isChanged()) {
422
+ return "The changes you made will be lost if you navigate away from this page.";
423
+ }
424
+ });
425
+ });
426
+ })(jQuery);
public/js/contenthash.js ADDED
@@ -0,0 +1,219 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @version $Id; contenthash.js 1.0 10:35:23 PM 15/01/2012 WipeOutMedia$
3
+ * Manage blocks content hashing.
4
+ * Content hashing is used to detect blocks data changing.
5
+ */
6
+
7
+ /**
8
+ * Content hashing class.
9
+ */
10
+ function ContentHash(options) {
11
+
12
+ /**
13
+ * jQuery object reference.
14
+ *
15
+ * @var jQuery.
16
+ */
17
+ var $ = jQuery;
18
+
19
+ /**
20
+ * Pointer to this object.
21
+ *
22
+ * @var [object ContentHash]
23
+ */
24
+ var $this = this;
25
+
26
+ /**
27
+ * List of fields that should affect the content hash.
28
+ *
29
+ * @var array
30
+ */
31
+ this.fields = ['code', 'block_name', 'location', 'links', 'scripts', 'page][', 'category]['];
32
+
33
+ /**
34
+ * Blocks manage form reference.
35
+ *
36
+ * @var HTMLForm
37
+ */
38
+ this.form = null;
39
+
40
+ /**
41
+ * Blocks hash list array.
42
+ *
43
+ * @var Array
44
+ */
45
+ this.hashList = [];
46
+
47
+ /**
48
+ * Options object.
49
+ *
50
+ * @var object
51
+ */
52
+ this.options = {};
53
+
54
+ /**
55
+ * Add new block to the hash list.
56
+ *
57
+ * This method should be called after a nw block is added.
58
+ *
59
+ * @param integer Block id.
60
+ * @return void
61
+ */
62
+ this.add = function(id) {
63
+ var blockHash = '';
64
+ if ($this.hashList[id] != undefined) {
65
+ $.error('block id is in use!');
66
+ }
67
+ else{
68
+ if ($this.options.UnsavedEmptyBlocks == 'createHash') {
69
+ blockHash = $this.getSingleBlockHash(id);
70
+ }
71
+ }
72
+ $this.hashList[id] = {
73
+ sync : false,
74
+ hash : blockHash
75
+ };
76
+ }
77
+
78
+ /**
79
+ * Clear hash list.
80
+ *
81
+ * @return void
82
+ */
83
+ this.clear = function() {
84
+ $this.hashList = [];
85
+ }
86
+
87
+ /**
88
+ * Delete block hash from the block list.
89
+ *
90
+ * This method should be called after deleting tthe block.
91
+ *
92
+ * @param integer Block id.
93
+ * @return void
94
+ */
95
+ this.deleteBlock = function(id) {
96
+ var block = {};
97
+ if ($this.hashList[id] == undefined) {
98
+ $.error('Block id not exists');
99
+ }
100
+ else {
101
+ block = $this.hashList[id];
102
+ // Delete only unsync (not saved on server) blocks.
103
+ // Deleting sync (saved on server) blocks broke detecing changes.
104
+ if (!block.sync) {
105
+ delete $this.hashList[id];
106
+ }
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Generate block hash list.
112
+ *
113
+ * The method find all the availbale block and create
114
+ * hash for each block.
115
+ *
116
+ * @return boolean
117
+ */
118
+ this.generate = function(reset) {
119
+ var blocks = $this.form.elements['blocks[]'];
120
+ // Make sure to delete all hashes first.
121
+ $this.clear();
122
+ // For $.each to behave correctly we need to wrap
123
+ // blocks in array if there is only one block available.
124
+ if (blocks.length == undefined) {
125
+ blocks = [blocks];
126
+ }
127
+ // Create new hashes.
128
+ $.each(blocks, function(){
129
+ var id = parseInt(this.value);
130
+ var blockNodeId = id + 1;
131
+ var blockHash = (reset == true) ? '' : $this.getSingleBlockHash(id);
132
+ var isSync = $('#cjtoolbox-' + blockNodeId + ' input[name="sync"]').val();
133
+ isSync = parseInt(isSync);
134
+ $this.hashList[id] = {
135
+ sync : isSync,
136
+ hash : blockHash
137
+ };
138
+ });
139
+ return true;
140
+ }
141
+
142
+ /**
143
+ * @internal
144
+ *
145
+ * Create hash for a single block.
146
+ *
147
+ * Create Hash from cjtoolbox array contents.
148
+ *
149
+ * @param integer Block id.
150
+ * @return string Block content MD5 hash.
151
+ */
152
+ this.getSingleBlockHash = function(id) {
153
+ // Block fields to detect.
154
+ var fieldVariableName = '';
155
+ var fieldElement = null;
156
+ var content = '';
157
+ var hash = '';
158
+ var blockNodeId = parseInt(id) + 1;
159
+ var isBlockExists = $('#cjtoolbox-' + blockNodeId).get(0);
160
+ // Check block existance, if deleted we should return hash('').
161
+ if (isBlockExists != undefined) {
162
+ // Get fields values from block.
163
+ $.each($this.fields, function(index, fieldName){
164
+ // build variable name.
165
+ fieldVariableName = 'cjtoolbox[' + id + '][' + fieldName + ']';
166
+ fieldElement = $this.form.elements[fieldVariableName];
167
+ // If the element is nodeList get all checkboxes element checked values.
168
+ if(fieldElement == '[object NodeList]') {
169
+ $.each(fieldElement, function() {
170
+ content += $(this).prop('checked');
171
+ });
172
+ }
173
+ else {
174
+ content += fieldElement.value;
175
+ }
176
+ });
177
+ }
178
+ hash = hex_md5(content);
179
+ return hash;
180
+ }
181
+ /**
182
+ * Initialize contentHash object.
183
+ *
184
+ * @return void
185
+ */
186
+ this.init = function() {
187
+ // Prepare options.
188
+ var defaultOptions = {
189
+ UnsavedEmptyBlocks : 'createHash' // Should unsaved/new blocks with no data changed treated as changes?
190
+ };
191
+ $this.options = $.extend(defaultOptions, options);
192
+ // Initialize variables for feature uses.
193
+ $this.form = document.getElementById('cjtoolbox_form');
194
+ }
195
+
196
+ /**
197
+ * Check if blocks data changed.
198
+ *
199
+ * @return boolean True if there is a change or false otherwise.
200
+ */
201
+ this.isChanged = function() {
202
+ var changed = false;
203
+ var targetHash = '';
204
+ $.each($this.hashList, function(id, block){
205
+ // Avoid array gaps.
206
+ if (block != undefined) {
207
+ targetHash = $this.getSingleBlockHash(id);
208
+ if (targetHash != block.hash) {
209
+ changed = true;
210
+ return;
211
+ }
212
+ }
213
+ });
214
+ return changed;
215
+ }
216
+ // Initialize object.
217
+ $this.init();
218
+
219
+ }
public/js/md5-min.js ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
3
+ * Digest Algorithm, as defined in RFC 1321.
4
+ * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
5
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
6
+ * Distributed under the BSD License
7
+ * See http://pajhome.org.uk/crypt/md5 for more info.
8
+ */
9
+ var hexcase=0;function hex_md5(a){return rstr2hex(rstr_md5(str2rstr_utf8(a)))}function hex_hmac_md5(a,b){return rstr2hex(rstr_hmac_md5(str2rstr_utf8(a),str2rstr_utf8(b)))}function md5_vm_test(){return hex_md5("abc").toLowerCase()=="900150983cd24fb0d6963f7d28e17f72"}function rstr_md5(a){return binl2rstr(binl_md5(rstr2binl(a),a.length*8))}function rstr_hmac_md5(c,f){var e=rstr2binl(c);if(e.length>16){e=binl_md5(e,c.length*8)}var a=Array(16),d=Array(16);for(var b=0;b<16;b++){a[b]=e[b]^909522486;d[b]=e[b]^1549556828}var g=binl_md5(a.concat(rstr2binl(f)),512+f.length*8);return binl2rstr(binl_md5(d.concat(g),512+128))}function rstr2hex(c){try{hexcase}catch(g){hexcase=0}var f=hexcase?"0123456789ABCDEF":"0123456789abcdef";var b="";var a;for(var d=0;d<c.length;d++){a=c.charCodeAt(d);b+=f.charAt((a>>>4)&15)+f.charAt(a&15)}return b}function str2rstr_utf8(c){var b="";var d=-1;var a,e;while(++d<c.length){a=c.charCodeAt(d);e=d+1<c.length?c.charCodeAt(d+1):0;if(55296<=a&&a<=56319&&56320<=e&&e<=57343){a=65536+((a&1023)<<10)+(e&1023);d++}if(a<=127){b+=String.fromCharCode(a)}else{if(a<=2047){b+=String.fromCharCode(192|((a>>>6)&31),128|(a&63))}else{if(a<=65535){b+=String.fromCharCode(224|((a>>>12)&15),128|((a>>>6)&63),128|(a&63))}else{if(a<=2097151){b+=String.fromCharCode(240|((a>>>18)&7),128|((a>>>12)&63),128|((a>>>6)&63),128|(a&63))}}}}}return b}function rstr2binl(b){var a=Array(b.length>>2);for(var c=0;c<a.length;c++){a[c]=0}for(var c=0;c<b.length*8;c+=8){a[c>>5]|=(b.charCodeAt(c/8)&255)<<(c%32)}return a}function binl2rstr(b){var a="";for(var c=0;c<b.length*32;c+=8){a+=String.fromCharCode((b[c>>5]>>>(c%32))&255)}return a}function binl_md5(p,k){p[k>>5]|=128<<((k)%32);p[(((k+64)>>>9)<<4)+14]=k;var o=1732584193;var n=-271733879;var m=-1732584194;var l=271733878;for(var g=0;g<p.length;g+=16){var j=o;var h=n;var f=m;var e=l;o=md5_ff(o,n,m,l,p[g+0],7,-680876936);l=md5_ff(l,o,n,m,p[g+1],12,-389564586);m=md5_ff(m,l,o,n,p[g+2],17,606105819);n=md5_ff(n,m,l,o,p[g+3],22,-1044525330);o=md5_ff(o,n,m,l,p[g+4],7,-176418897);l=md5_ff(l,o,n,m,p[g+5],12,1200080426);m=md5_ff(m,l,o,n,p[g+6],17,-1473231341);n=md5_ff(n,m,l,o,p[g+7],22,-45705983);o=md5_ff(o,n,m,l,p[g+8],7,1770035416);l=md5_ff(l,o,n,m,p[g+9],12,-1958414417);m=md5_ff(m,l,o,n,p[g+10],17,-42063);n=md5_ff(n,m,l,o,p[g+11],22,-1990404162);o=md5_ff(o,n,m,l,p[g+12],7,1804603682);l=md5_ff(l,o,n,m,p[g+13],12,-40341101);m=md5_ff(m,l,o,n,p[g+14],17,-1502002290);n=md5_ff(n,m,l,o,p[g+15],22,1236535329);o=md5_gg(o,n,m,l,p[g+1],5,-165796510);l=md5_gg(l,o,n,m,p[g+6],9,-1069501632);m=md5_gg(m,l,o,n,p[g+11],14,643717713);n=md5_gg(n,m,l,o,p[g+0],20,-373897302);o=md5_gg(o,n,m,l,p[g+5],5,-701558691);l=md5_gg(l,o,n,m,p[g+10],9,38016083);m=md5_gg(m,l,o,n,p[g+15],14,-660478335);n=md5_gg(n,m,l,o,p[g+4],20,-405537848);o=md5_gg(o,n,m,l,p[g+9],5,568446438);l=md5_gg(l,o,n,m,p[g+14],9,-1019803690);m=md5_gg(m,l,o,n,p[g+3],14,-187363961);n=md5_gg(n,m,l,o,p[g+8],20,1163531501);o=md5_gg(o,n,m,l,p[g+13],5,-1444681467);l=md5_gg(l,o,n,m,p[g+2],9,-51403784);m=md5_gg(m,l,o,n,p[g+7],14,1735328473);n=md5_gg(n,m,l,o,p[g+12],20,-1926607734);o=md5_hh(o,n,m,l,p[g+5],4,-378558);l=md5_hh(l,o,n,m,p[g+8],11,-2022574463);m=md5_hh(m,l,o,n,p[g+11],16,1839030562);n=md5_hh(n,m,l,o,p[g+14],23,-35309556);o=md5_hh(o,n,m,l,p[g+1],4,-1530992060);l=md5_hh(l,o,n,m,p[g+4],11,1272893353);m=md5_hh(m,l,o,n,p[g+7],16,-155497632);n=md5_hh(n,m,l,o,p[g+10],23,-1094730640);o=md5_hh(o,n,m,l,p[g+13],4,681279174);l=md5_hh(l,o,n,m,p[g+0],11,-358537222);m=md5_hh(m,l,o,n,p[g+3],16,-722521979);n=md5_hh(n,m,l,o,p[g+6],23,76029189);o=md5_hh(o,n,m,l,p[g+9],4,-640364487);l=md5_hh(l,o,n,m,p[g+12],11,-421815835);m=md5_hh(m,l,o,n,p[g+15],16,530742520);n=md5_hh(n,m,l,o,p[g+2],23,-995338651);o=md5_ii(o,n,m,l,p[g+0],6,-198630844);l=md5_ii(l,o,n,m,p[g+7],10,1126891415);m=md5_ii(m,l,o,n,p[g+14],15,-1416354905);n=md5_ii(n,m,l,o,p[g+5],21,-57434055);o=md5_ii(o,n,m,l,p[g+12],6,1700485571);l=md5_ii(l,o,n,m,p[g+3],10,-1894986606);m=md5_ii(m,l,o,n,p[g+10],15,-1051523);n=md5_ii(n,m,l,o,p[g+1],21,-2054922799);o=md5_ii(o,n,m,l,p[g+8],6,1873313359);l=md5_ii(l,o,n,m,p[g+15],10,-30611744);m=md5_ii(m,l,o,n,p[g+6],15,-1560198380);n=md5_ii(n,m,l,o,p[g+13],21,1309151649);o=md5_ii(o,n,m,l,p[g+4],6,-145523070);l=md5_ii(l,o,n,m,p[g+11],10,-1120210379);m=md5_ii(m,l,o,n,p[g+2],15,718787259);n=md5_ii(n,m,l,o,p[g+9],21,-343485551);o=safe_add(o,j);n=safe_add(n,h);m=safe_add(m,f);l=safe_add(l,e)}return Array(o,n,m,l)}function md5_cmn(h,e,d,c,g,f){return safe_add(bit_rol(safe_add(safe_add(e,h),safe_add(c,f)),g),d)}function md5_ff(g,f,k,j,e,i,h){return md5_cmn((f&k)|((~f)&j),g,f,e,i,h)}function md5_gg(g,f,k,j,e,i,h){return md5_cmn((f&j)|(k&(~j)),g,f,e,i,h)}function md5_hh(g,f,k,j,e,i,h){return md5_cmn(f^k^j,g,f,e,i,h)}function md5_ii(g,f,k,j,e,i,h){return md5_cmn(k^(f|(~j)),g,f,e,i,h)}function safe_add(a,d){var c=(a&65535)+(d&65535);var b=(a>>16)+(d>>16)+(c>>16);return(b<<16)|(c&65535)}function bit_rol(a,b){return(a<<b)|(a>>>(32-b))};
public/js/upload/jquery.cycle.all.min.js ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * jQuery Cycle Plugin (with Transition Definitions)
3
+ * Examples and documentation at: http://jquery.malsup.com/cycle/
4
+ * Copyright (c) 2007-2009 M. Alsup
5
+ * Version: 2.65 (07-APR-2009)
6
+ * Dual licensed under the MIT and GPL licenses:
7
+ * http://www.opensource.org/licenses/mit-license.php
8
+ * http://www.gnu.org/licenses/gpl.html
9
+ * Requires: jQuery v1.2.6 or later
10
+ *
11
+ * Originally based on the work of:
12
+ * 1) Matt Oakes
13
+ * 2) Torsten Baldes (http://medienfreunde.com/lab/innerfade/)
14
+ * 3) Benjamin Sterling (http://www.benjaminsterling.com/experiments/jqShuffle/)
15
+ */
16
+ ;(function($){var ver="2.65";if($.support==undefined){$.support={opacity:!($.browser.msie)};}function log(){if(window.console&&window.console.log){window.console.log("[cycle] "+Array.prototype.join.call(arguments," "));}}$.fn.cycle=function(options,arg2){var o={s:this.selector,c:this.context};if(this.length==0&&options!="stop"){if(!$.isReady&&o.s){log("DOM not ready, queuing slideshow");$(function(){$(o.s,o.c).cycle(options,arg2);});return this;}log("terminating; zero elements found by selector"+($.isReady?"":" (DOM not ready)"));return this;}return this.each(function(){options=handleArguments(this,options,arg2);if(options===false){return;}if(this.cycleTimeout){clearTimeout(this.cycleTimeout);}this.cycleTimeout=this.cyclePause=0;var $cont=$(this);var $slides=options.slideExpr?$(options.slideExpr,this):$cont.children();var els=$slides.get();if(els.length<2){log("terminating; too few slides: "+els.length);return;}var opts=buildOptions($cont,$slides,els,options,o);if(opts===false){return;}if(opts.timeout||opts.continuous){this.cycleTimeout=setTimeout(function(){go(els,opts,0,!opts.rev);},opts.continuous?10:opts.timeout+(opts.delay||0));}});};function handleArguments(cont,options,arg2){if(cont.cycleStop==undefined){cont.cycleStop=0;}if(options===undefined||options===null){options={};}if(options.constructor==String){switch(options){case"stop":cont.cycleStop++;if(cont.cycleTimeout){clearTimeout(cont.cycleTimeout);}cont.cycleTimeout=0;$(cont).removeData("cycle.opts");return false;case"pause":cont.cyclePause=1;return false;case"resume":cont.cyclePause=0;if(arg2===true){options=$(cont).data("cycle.opts");if(!options){log("options not found, can not resume");return false;}if(cont.cycleTimeout){clearTimeout(cont.cycleTimeout);cont.cycleTimeout=0;}go(options.elements,options,1,1);}return false;default:options={fx:options};}}else{if(options.constructor==Number){var num=options;options=$(cont).data("cycle.opts");if(!options){log("options not found, can not advance slide");return false;}if(num<0||num>=options.elements.length){log("invalid slide index: "+num);return false;}options.nextSlide=num;if(cont.cycleTimeout){clearTimeout(cont.cycleTimeout);cont.cycleTimeout=0;}if(typeof arg2=="string"){options.oneTimeFx=arg2;}go(options.elements,options,1,num>=options.currSlide);return false;}}return options;}function removeFilter(el,opts){if(!$.support.opacity&&opts.cleartype&&el.style.filter){try{el.style.removeAttribute("filter");}catch(smother){}}}function buildOptions($cont,$slides,els,options,o){var opts=$.extend({},$.fn.cycle.defaults,options||{},$.metadata?$cont.metadata():$.meta?$cont.data():{});if(opts.autostop){opts.countdown=opts.autostopCount||els.length;}var cont=$cont[0];$cont.data("cycle.opts",opts);opts.$cont=$cont;opts.stopCount=cont.cycleStop;opts.elements=els;opts.before=opts.before?[opts.before]:[];opts.after=opts.after?[opts.after]:[];opts.after.unshift(function(){opts.busy=0;});if(!$.support.opacity&&opts.cleartype){opts.after.push(function(){removeFilter(this,opts);});}if(opts.continuous){opts.after.push(function(){go(els,opts,0,!opts.rev);});}saveOriginalOpts(opts);if(!$.support.opacity&&opts.cleartype&&!opts.cleartypeNoBg){clearTypeFix($slides);}if($cont.css("position")=="static"){$cont.css("position","relative");}if(opts.width){$cont.width(opts.width);}if(opts.height&&opts.height!="auto"){$cont.height(opts.height);}if(opts.startingSlide){opts.startingSlide=parseInt(opts.startingSlide);}if(opts.random){opts.randomMap=[];for(var i=0;i<els.length;i++){opts.randomMap.push(i);}opts.randomMap.sort(function(a,b){return Math.random()-0.5;});opts.randomIndex=0;opts.startingSlide=opts.randomMap[0];}else{if(opts.startingSlide>=els.length){opts.startingSlide=0;}}opts.currSlide=opts.startingSlide=opts.startingSlide||0;var first=opts.startingSlide;$slides.css({position:"absolute",top:0,left:0}).hide().each(function(i){var z=first?i>=first?els.length-(i-first):first-i:els.length-i;$(this).css("z-index",z);});$(els[first]).css("opacity",1).show();removeFilter(els[first],opts);if(opts.fit&&opts.width){$slides.width(opts.width);}if(opts.fit&&opts.height&&opts.height!="auto"){$slides.height(opts.height);}var reshape=opts.containerResize&&!$cont.innerHeight();if(reshape){var maxw=0,maxh=0;for(var i=0;i<els.length;i++){var $e=$(els[i]),e=$e[0],w=$e.outerWidth(),h=$e.outerHeight();if(!w){w=e.offsetWidth;}if(!h){h=e.offsetHeight;}maxw=w>maxw?w:maxw;maxh=h>maxh?h:maxh;}if(maxw>0&&maxh>0){$cont.css({width:maxw+"px",height:maxh+"px"});}}if(opts.pause){$cont.hover(function(){this.cyclePause++;},function(){this.cyclePause--;});}if(supportMultiTransitions(opts)===false){return false;}if(!opts.multiFx){var init=$.fn.cycle.transitions[opts.fx];if($.isFunction(init)){init($cont,$slides,opts);}else{if(opts.fx!="custom"&&!opts.multiFx){log("unknown transition: "+opts.fx,"; slideshow terminating");return false;}}}var requeue=false;options.requeueAttempts=options.requeueAttempts||0;$slides.each(function(){var $el=$(this);this.cycleH=(opts.fit&&opts.height)?opts.height:$el.height();this.cycleW=(opts.fit&&opts.width)?opts.width:$el.width();if($el.is("img")){var loadingIE=($.browser.msie&&this.cycleW==28&&this.cycleH==30&&!this.complete);var loadingOp=($.browser.opera&&this.cycleW==42&&this.cycleH==19&&!this.complete);var loadingOther=(this.cycleH==0&&this.cycleW==0&&!this.complete);if(loadingIE||loadingOp||loadingOther){if(o.s&&opts.requeueOnImageNotLoaded&&++options.requeueAttempts<100){log(options.requeueAttempts," - img slide not loaded, requeuing slideshow: ",this.src,this.cycleW,this.cycleH);setTimeout(function(){$(o.s,o.c).cycle(options);},opts.requeueTimeout);requeue=true;return false;}else{log("could not determine size of image: "+this.src,this.cycleW,this.cycleH);}}}return true;});if(requeue){return false;}opts.cssBefore=opts.cssBefore||{};opts.animIn=opts.animIn||{};opts.animOut=opts.animOut||{};$slides.not(":eq("+first+")").css(opts.cssBefore);if(opts.cssFirst){$($slides[first]).css(opts.cssFirst);}if(opts.timeout){opts.timeout=parseInt(opts.timeout);if(opts.speed.constructor==String){opts.speed=$.fx.speeds[opts.speed]||parseInt(opts.speed);}if(!opts.sync){opts.speed=opts.speed/2;}while((opts.timeout-opts.speed)<250){opts.timeout+=opts.speed;}}if(opts.easing){opts.easeIn=opts.easeOut=opts.easing;}if(!opts.speedIn){opts.speedIn=opts.speed;}if(!opts.speedOut){opts.speedOut=opts.speed;}opts.slideCount=els.length;opts.currSlide=opts.lastSlide=first;if(opts.random){opts.nextSlide=opts.currSlide;if(++opts.randomIndex==els.length){opts.randomIndex=0;}opts.nextSlide=opts.randomMap[opts.randomIndex];}else{opts.nextSlide=opts.startingSlide>=(els.length-1)?0:opts.startingSlide+1;}var e0=$slides[first];if(opts.before.length){opts.before[0].apply(e0,[e0,e0,opts,true]);}if(opts.after.length>1){opts.after[1].apply(e0,[e0,e0,opts,true]);}if(opts.next){$(opts.next).click(function(){return advance(opts,opts.rev?-1:1);});}if(opts.prev){$(opts.prev).click(function(){return advance(opts,opts.rev?1:-1);});}if(opts.pager){buildPager(els,opts);}exposeAddSlide(opts,els);return opts;}function saveOriginalOpts(opts){opts.original={before:[],after:[]};opts.original.cssBefore=$.extend({},opts.cssBefore);opts.original.cssAfter=$.extend({},opts.cssAfter);opts.original.animIn=$.extend({},opts.animIn);opts.original.animOut=$.extend({},opts.animOut);$.each(opts.before,function(){opts.original.before.push(this);});$.each(opts.after,function(){opts.original.after.push(this);});}function supportMultiTransitions(opts){var txs=$.fn.cycle.transitions;if(opts.fx.indexOf(",")>0){opts.multiFx=true;opts.fxs=opts.fx.replace(/\s*/g,"").split(",");for(var i=0;i<opts.fxs.length;i++){var fx=opts.fxs[i];var tx=txs[fx];if(!tx||!txs.hasOwnProperty(fx)||!$.isFunction(tx)){log("discarding unknown transition: ",fx);opts.fxs.splice(i,1);i--;}}if(!opts.fxs.length){log("No valid transitions named; slideshow terminating.");return false;}}else{if(opts.fx=="all"){opts.multiFx=true;opts.fxs=[];for(p in txs){var tx=txs[p];if(txs.hasOwnProperty(p)&&$.isFunction(tx)){opts.fxs.push(p);}}}}if(opts.multiFx&&opts.randomizeEffects){var r1=Math.floor(Math.random()*20)+30;for(var i=0;i<r1;i++){var r2=Math.floor(Math.random()*opts.fxs.length);opts.fxs.push(opts.fxs.splice(r2,1)[0]);}log("randomized fx sequence: ",opts.fxs);}return true;}function exposeAddSlide(opts,els){opts.addSlide=function(newSlide,prepend){var $s=$(newSlide),s=$s[0];if(!opts.autostopCount){opts.countdown++;}els[prepend?"unshift":"push"](s);if(opts.els){opts.els[prepend?"unshift":"push"](s);}opts.slideCount=els.length;$s.css("position","absolute");$s[prepend?"prependTo":"appendTo"](opts.$cont);if(prepend){opts.currSlide++;opts.nextSlide++;}if(!$.support.opacity&&opts.cleartype&&!opts.cleartypeNoBg){clearTypeFix($s);}if(opts.fit&&opts.width){$s.width(opts.width);}if(opts.fit&&opts.height&&opts.height!="auto"){$slides.height(opts.height);}s.cycleH=(opts.fit&&opts.height)?opts.height:$s.height();s.cycleW=(opts.fit&&opts.width)?opts.width:$s.width();$s.css(opts.cssBefore);if(opts.pager){$.fn.cycle.createPagerAnchor(els.length-1,s,$(opts.pager),els,opts);}if($.isFunction(opts.onAddSlide)){opts.onAddSlide($s);}else{$s.hide();}};}$.fn.cycle.resetState=function(opts,fx){fx=fx||opts.fx;opts.before=[];opts.after=[];opts.cssBefore=$.extend({},opts.original.cssBefore);opts.cssAfter=$.extend({},opts.original.cssAfter);opts.animIn=$.extend({},opts.original.animIn);opts.animOut=$.extend({},opts.original.animOut);opts.fxFn=null;$.each(opts.original.before,function(){opts.before.push(this);});$.each(opts.original.after,function(){opts.after.push(this);});var init=$.fn.cycle.transitions[fx];if($.isFunction(init)){init(opts.$cont,$(opts.elements),opts);}};function go(els,opts,manual,fwd){if(manual&&opts.busy&&opts.manualTrump){$(els).stop(true,true);opts.busy=false;}if(opts.busy){return;}var p=opts.$cont[0],curr=els[opts.currSlide],next=els[opts.nextSlide];if(p.cycleStop!=opts.stopCount||p.cycleTimeout===0&&!manual){return;}if(!manual&&!p.cyclePause&&((opts.autostop&&(--opts.countdown<=0))||(opts.nowrap&&!opts.random&&opts.nextSlide<opts.currSlide))){if(opts.end){opts.end(opts);}return;}if(manual||!p.cyclePause){var fx=opts.fx;curr.cycleH=curr.cycleH||$(curr).height();curr.cycleW=curr.cycleW||$(curr).width();next.cycleH=next.cycleH||$(next).height();next.cycleW=next.cycleW||$(next).width();if(opts.multiFx){if(opts.lastFx==undefined||++opts.lastFx>=opts.fxs.length){opts.lastFx=0;}fx=opts.fxs[opts.lastFx];opts.currFx=fx;}if(opts.oneTimeFx){fx=opts.oneTimeFx;opts.oneTimeFx=null;}$.fn.cycle.resetState(opts,fx);if(opts.before.length){$.each(opts.before,function(i,o){if(p.cycleStop!=opts.stopCount){return;}o.apply(next,[curr,next,opts,fwd]);});}var after=function(){$.each(opts.after,function(i,o){if(p.cycleStop!=opts.stopCount){return;}o.apply(next,[curr,next,opts,fwd]);});};if(opts.nextSlide!=opts.currSlide){opts.busy=1;if(opts.fxFn){opts.fxFn(curr,next,opts,after,fwd);}else{if($.isFunction($.fn.cycle[opts.fx])){$.fn.cycle[opts.fx](curr,next,opts,after);}else{$.fn.cycle.custom(curr,next,opts,after,manual&&opts.fastOnEvent);}}}opts.lastSlide=opts.currSlide;if(opts.random){opts.currSlide=opts.nextSlide;if(++opts.randomIndex==els.length){opts.randomIndex=0;}opts.nextSlide=opts.randomMap[opts.randomIndex];}else{var roll=(opts.nextSlide+1)==els.length;opts.nextSlide=roll?0:opts.nextSlide+1;opts.currSlide=roll?els.length-1:opts.nextSlide-1;}if(opts.pager){$.fn.cycle.updateActivePagerLink(opts.pager,opts.currSlide);}}var ms=0;if(opts.timeout&&!opts.continuous){ms=getTimeout(curr,next,opts,fwd);}else{if(opts.continuous&&p.cyclePause){ms=10;}}if(ms>0){p.cycleTimeout=setTimeout(function(){go(els,opts,0,!opts.rev);},ms);}}$.fn.cycle.updateActivePagerLink=function(pager,currSlide){$(pager).find("a").removeClass("activeSlide").filter("a:eq("+currSlide+")").addClass("activeSlide");};function getTimeout(curr,next,opts,fwd){if(opts.timeoutFn){var t=opts.timeoutFn(curr,next,opts,fwd);if(t!==false){return t;}}return opts.timeout;}$.fn.cycle.next=function(opts){advance(opts,opts.rev?-1:1);};$.fn.cycle.prev=function(opts){advance(opts,opts.rev?1:-1);};function advance(opts,val){var els=opts.elements;var p=opts.$cont[0],timeout=p.cycleTimeout;if(timeout){clearTimeout(timeout);p.cycleTimeout=0;}if(opts.random&&val<0){opts.randomIndex--;if(--opts.randomIndex==-2){opts.randomIndex=els.length-2;}else{if(opts.randomIndex==-1){opts.randomIndex=els.length-1;}}opts.nextSlide=opts.randomMap[opts.randomIndex];}else{if(opts.random){if(++opts.randomIndex==els.length){opts.randomIndex=0;}opts.nextSlide=opts.randomMap[opts.randomIndex];}else{opts.nextSlide=opts.currSlide+val;if(opts.nextSlide<0){if(opts.nowrap){return false;}opts.nextSlide=els.length-1;}else{if(opts.nextSlide>=els.length){if(opts.nowrap){return false;}opts.nextSlide=0;}}}}if($.isFunction(opts.prevNextClick)){opts.prevNextClick(val>0,opts.nextSlide,els[opts.nextSlide]);}go(els,opts,1,val>=0);return false;}function buildPager(els,opts){var $p=$(opts.pager);$.each(els,function(i,o){$.fn.cycle.createPagerAnchor(i,o,$p,els,opts);});$.fn.cycle.updateActivePagerLink(opts.pager,opts.startingSlide);}$.fn.cycle.createPagerAnchor=function(i,el,$p,els,opts){var a=($.isFunction(opts.pagerAnchorBuilder))?opts.pagerAnchorBuilder(i,el):'<a href="#">'+(i+1)+"</a>";if(!a){return;}var $a=$(a);if($a.parents("body").length==0){var arr=[];if($p.length>1){$p.each(function(){var $clone=$a.clone(true);$(this).append($clone);arr.push($clone);});$a=$(arr);}else{$a.appendTo($p);}}$a.bind(opts.pagerEvent,function(){opts.nextSlide=i;var p=opts.$cont[0],timeout=p.cycleTimeout;if(timeout){clearTimeout(timeout);p.cycleTimeout=0;}if($.isFunction(opts.pagerClick)){opts.pagerClick(opts.nextSlide,els[opts.nextSlide]);}go(els,opts,1,opts.currSlide<i);return false;});if(opts.pauseOnPagerHover){$a.hover(function(){opts.$cont[0].cyclePause++;},function(){opts.$cont[0].cyclePause--;});}};$.fn.cycle.hopsFromLast=function(opts,fwd){var hops,l=opts.lastSlide,c=opts.currSlide;if(fwd){hops=c>l?c-l:opts.slideCount-l;}else{hops=c<l?l-c:l+opts.slideCount-c;}return hops;};function clearTypeFix($slides){function hex(s){s=parseInt(s).toString(16);return s.length<2?"0"+s:s;}function getBg(e){for(;e&&e.nodeName.toLowerCase()!="html";e=e.parentNode){var v=$.css(e,"background-color");if(v.indexOf("rgb")>=0){var rgb=v.match(/\d+/g);return"#"+hex(rgb[0])+hex(rgb[1])+hex(rgb[2]);}if(v&&v!="transparent"){return v;}}return"#ffffff";}$slides.each(function(){$(this).css("background-color",getBg(this));});}$.fn.cycle.commonReset=function(curr,next,opts,w,h,rev){$(opts.elements).not(curr).hide();opts.cssBefore.opacity=1;opts.cssBefore.display="block";if(w!==false&&next.cycleW>0){opts.cssBefore.width=next.cycleW;}if(h!==false&&next.cycleH>0){opts.cssBefore.height=next.cycleH;}opts.cssAfter=opts.cssAfter||{};opts.cssAfter.display="none";$(curr).css("zIndex",opts.slideCount+(rev===true?1:0));$(next).css("zIndex",opts.slideCount+(rev===true?0:1));};$.fn.cycle.custom=function(curr,next,opts,cb,speedOverride){var $l=$(curr),$n=$(next);var speedIn=opts.speedIn,speedOut=opts.speedOut,easeIn=opts.easeIn,easeOut=opts.easeOut;$n.css(opts.cssBefore);if(speedOverride){if(typeof speedOverride=="number"){speedIn=speedOut=speedOverride;}else{speedIn=speedOut=1;}easeIn=easeOut=null;}var fn=function(){$n.animate(opts.animIn,speedIn,easeIn,cb);};$l.animate(opts.animOut,speedOut,easeOut,function(){if(opts.cssAfter){$l.css(opts.cssAfter);}if(!opts.sync){fn();}});if(opts.sync){fn();}};$.fn.cycle.transitions={fade:function($cont,$slides,opts){$slides.not(":eq("+opts.currSlide+")").css("opacity",0);opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts);opts.cssBefore.opacity=0;});opts.animIn={opacity:1};opts.animOut={opacity:0};opts.cssBefore={top:0,left:0};}};$.fn.cycle.ver=function(){return ver;};$.fn.cycle.defaults={fx:"fade",timeout:4000,timeoutFn:null,continuous:0,speed:1000,speedIn:null,speedOut:null,next:null,prev:null,prevNextClick:null,pager:null,pagerClick:null,pagerEvent:"click",pagerAnchorBuilder:null,before:null,after:null,end:null,easing:null,easeIn:null,easeOut:null,shuffle:null,animIn:null,animOut:null,cssBefore:null,cssAfter:null,fxFn:null,height:"auto",startingSlide:0,sync:1,random:0,fit:0,containerResize:1,pause:0,pauseOnPagerHover:0,autostop:0,autostopCount:0,delay:0,slideExpr:null,cleartype:!$.support.opacity,nowrap:0,fastOnEvent:0,randomizeEffects:1,rev:0,manualTrump:true,requeueOnImageNotLoaded:true,requeueTimeout:250};})(jQuery);
17
+
18
+ /*
19
+ * jQuery Cycle Plugin Transition Definitions
20
+ * This script is a plugin for the jQuery Cycle Plugin
21
+ * Examples and documentation at: http://malsup.com/jquery/cycle/
22
+ * Copyright (c) 2007-2008 M. Alsup
23
+ * Version: 2.52
24
+ * Dual licensed under the MIT and GPL licenses:
25
+ * http://www.opensource.org/licenses/mit-license.php
26
+ * http://www.gnu.org/licenses/gpl.html
27
+ */
28
+ ;(function($){$.fn.cycle.transitions.scrollUp=function($cont,$slides,opts){$cont.css("overflow","hidden");opts.before.push($.fn.cycle.commonReset);var h=$cont.height();opts.cssBefore={top:h,left:0};opts.cssFirst={top:0};opts.animIn={top:0};opts.animOut={top:-h};};$.fn.cycle.transitions.scrollDown=function($cont,$slides,opts){$cont.css("overflow","hidden");opts.before.push($.fn.cycle.commonReset);var h=$cont.height();opts.cssFirst={top:0};opts.cssBefore={top:-h,left:0};opts.animIn={top:0};opts.animOut={top:h};};$.fn.cycle.transitions.scrollLeft=function($cont,$slides,opts){$cont.css("overflow","hidden");opts.before.push($.fn.cycle.commonReset);var w=$cont.width();opts.cssFirst={left:0};opts.cssBefore={left:w,top:0};opts.animIn={left:0};opts.animOut={left:0-w};};$.fn.cycle.transitions.scrollRight=function($cont,$slides,opts){$cont.css("overflow","hidden");opts.before.push($.fn.cycle.commonReset);var w=$cont.width();opts.cssFirst={left:0};opts.cssBefore={left:-w,top:0};opts.animIn={left:0};opts.animOut={left:w};};$.fn.cycle.transitions.scrollHorz=function($cont,$slides,opts){$cont.css("overflow","hidden").width();opts.before.push(function(curr,next,opts,fwd){$.fn.cycle.commonReset(curr,next,opts);opts.cssBefore.left=fwd?(next.cycleW-1):(1-next.cycleW);opts.animOut.left=fwd?-curr.cycleW:curr.cycleW;});opts.cssFirst={left:0};opts.cssBefore={top:0};opts.animIn={left:0};opts.animOut={top:0};};$.fn.cycle.transitions.scrollVert=function($cont,$slides,opts){$cont.css("overflow","hidden");opts.before.push(function(curr,next,opts,fwd){$.fn.cycle.commonReset(curr,next,opts);opts.cssBefore.top=fwd?(1-next.cycleH):(next.cycleH-1);opts.animOut.top=fwd?curr.cycleH:-curr.cycleH;});opts.cssFirst={top:0};opts.cssBefore={left:0};opts.animIn={top:0};opts.animOut={left:0};};$.fn.cycle.transitions.slideX=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$(opts.elements).not(curr).hide();$.fn.cycle.commonReset(curr,next,opts,false,true);opts.animIn.width=next.cycleW;});opts.cssBefore={left:0,top:0,width:0};opts.animIn={width:"show"};opts.animOut={width:0};};$.fn.cycle.transitions.slideY=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$(opts.elements).not(curr).hide();$.fn.cycle.commonReset(curr,next,opts,true,false);opts.animIn.height=next.cycleH;});opts.cssBefore={left:0,top:0,height:0};opts.animIn={height:"show"};opts.animOut={height:0};};$.fn.cycle.transitions.shuffle=function($cont,$slides,opts){var w=$cont.css("overflow","visible").width();$slides.css({left:0,top:0});opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,true,true,true);});opts.speed=opts.speed/2;opts.random=0;opts.shuffle=opts.shuffle||{left:-w,top:15};opts.els=[];for(var i=0;i<$slides.length;i++){opts.els.push($slides[i]);}for(var i=0;i<opts.currSlide;i++){opts.els.push(opts.els.shift());}opts.fxFn=function(curr,next,opts,cb,fwd){var $el=fwd?$(curr):$(next);$(next).css(opts.cssBefore);var count=opts.slideCount;$el.animate(opts.shuffle,opts.speedIn,opts.easeIn,function(){var hops=$.fn.cycle.hopsFromLast(opts,fwd);for(var k=0;k<hops;k++){fwd?opts.els.push(opts.els.shift()):opts.els.unshift(opts.els.pop());}if(fwd){for(var i=0,len=opts.els.length;i<len;i++){$(opts.els[i]).css("z-index",len-i+count);}}else{var z=$(curr).css("z-index");$el.css("z-index",parseInt(z)+1+count);}$el.animate({left:0,top:0},opts.speedOut,opts.easeOut,function(){$(fwd?this:curr).hide();if(cb){cb();}});});};opts.cssBefore={display:"block",opacity:1,top:0,left:0};};$.fn.cycle.transitions.turnUp=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,true,false);opts.cssBefore.top=next.cycleH;opts.animIn.height=next.cycleH;});opts.cssFirst={top:0};opts.cssBefore={left:0,height:0};opts.animIn={top:0};opts.animOut={height:0};};$.fn.cycle.transitions.turnDown=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,true,false);opts.animIn.height=next.cycleH;opts.animOut.top=curr.cycleH;});opts.cssFirst={top:0};opts.cssBefore={left:0,top:0,height:0};opts.animOut={height:0};};$.fn.cycle.transitions.turnLeft=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,false,true);opts.cssBefore.left=next.cycleW;opts.animIn.width=next.cycleW;});opts.cssBefore={top:0,width:0};opts.animIn={left:0};opts.animOut={width:0};};$.fn.cycle.transitions.turnRight=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,false,true);opts.animIn.width=next.cycleW;opts.animOut.left=curr.cycleW;});opts.cssBefore={top:0,left:0,width:0};opts.animIn={left:0};opts.animOut={width:0};};$.fn.cycle.transitions.zoom=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,false,false,true);opts.cssBefore.top=next.cycleH/2;opts.cssBefore.left=next.cycleW/2;opts.animIn={top:0,left:0,width:next.cycleW,height:next.cycleH};opts.animOut={width:0,height:0,top:curr.cycleH/2,left:curr.cycleW/2};});opts.cssFirst={top:0,left:0};opts.cssBefore={width:0,height:0};};$.fn.cycle.transitions.fadeZoom=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,false,false);opts.cssBefore.left=next.cycleW/2;opts.cssBefore.top=next.cycleH/2;opts.animIn={top:0,left:0,width:next.cycleW,height:next.cycleH};});opts.cssBefore={width:0,height:0};opts.animOut={opacity:0};};$.fn.cycle.transitions.blindX=function($cont,$slides,opts){var w=$cont.css("overflow","hidden").width();opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts);opts.animIn.width=next.cycleW;opts.animOut.left=curr.cycleW;});opts.cssBefore={left:w,top:0};opts.animIn={left:0};opts.animOut={left:w};};$.fn.cycle.transitions.blindY=function($cont,$slides,opts){var h=$cont.css("overflow","hidden").height();opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts);opts.animIn.height=next.cycleH;opts.animOut.top=curr.cycleH;});opts.cssBefore={top:h,left:0};opts.animIn={top:0};opts.animOut={top:h};};$.fn.cycle.transitions.blindZ=function($cont,$slides,opts){var h=$cont.css("overflow","hidden").height();var w=$cont.width();opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts);opts.animIn.height=next.cycleH;opts.animOut.top=curr.cycleH;});opts.cssBefore={top:h,left:w};opts.animIn={top:0,left:0};opts.animOut={top:h,left:w};};$.fn.cycle.transitions.growX=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,false,true);opts.cssBefore.left=this.cycleW/2;opts.animIn={left:0,width:this.cycleW};opts.animOut={left:0};});opts.cssBefore={width:0,top:0};};$.fn.cycle.transitions.growY=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,true,false);opts.cssBefore.top=this.cycleH/2;opts.animIn={top:0,height:this.cycleH};opts.animOut={top:0};});opts.cssBefore={height:0,left:0};};$.fn.cycle.transitions.curtainX=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,false,true,true);opts.cssBefore.left=next.cycleW/2;opts.animIn={left:0,width:this.cycleW};opts.animOut={left:curr.cycleW/2,width:0};});opts.cssBefore={top:0,width:0};};$.fn.cycle.transitions.curtainY=function($cont,$slides,opts){opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,true,false,true);opts.cssBefore.top=next.cycleH/2;opts.animIn={top:0,height:next.cycleH};opts.animOut={top:curr.cycleH/2,height:0};});opts.cssBefore={left:0,height:0};};$.fn.cycle.transitions.cover=function($cont,$slides,opts){var d=opts.direction||"left";var w=$cont.css("overflow","hidden").width();var h=$cont.height();opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts);if(d=="right"){opts.cssBefore.left=-w;}else{if(d=="up"){opts.cssBefore.top=h;}else{if(d=="down"){opts.cssBefore.top=-h;}else{opts.cssBefore.left=w;}}}});opts.animIn={left:0,top:0};opts.animOut={opacity:1};opts.cssBefore={top:0,left:0};};$.fn.cycle.transitions.uncover=function($cont,$slides,opts){var d=opts.direction||"left";var w=$cont.css("overflow","hidden").width();var h=$cont.height();opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,true,true,true);if(d=="right"){opts.animOut.left=w;}else{if(d=="up"){opts.animOut.top=-h;}else{if(d=="down"){opts.animOut.top=h;}else{opts.animOut.left=-w;}}}});opts.animIn={left:0,top:0};opts.animOut={opacity:1};opts.cssBefore={top:0,left:0};};$.fn.cycle.transitions.toss=function($cont,$slides,opts){var w=$cont.css("overflow","visible").width();var h=$cont.height();opts.before.push(function(curr,next,opts){$.fn.cycle.commonReset(curr,next,opts,true,true,true);if(!opts.animOut.left&&!opts.animOut.top){opts.animOut={left:w*2,top:-h/2,opacity:0};}else{opts.animOut.opacity=0;}});opts.cssBefore={left:0,top:0};opts.animIn={left:0};};$.fn.cycle.transitions.wipe=function($cont,$slides,opts){var w=$cont.css("overflow","hidden").width();var h=$cont.height();opts.cssBefore=opts.cssBefore||{};var clip;if(opts.clip){if(/l2r/.test(opts.clip)){clip="rect(0px 0px "+h+"px 0px)";}else{if(/r2l/.test(opts.clip)){clip="rect(0px "+w+"px "+h+"px "+w+"px)";}else{if(/t2b/.test(opts.clip)){clip="rect(0px "+w+"px 0px 0px)";}else{if(/b2t/.test(opts.clip)){clip="rect("+h+"px "+w+"px "+h+"px 0px)";}else{if(/zoom/.test(opts.clip)){var t=parseInt(h/2);var l=parseInt(w/2);clip="rect("+t+"px "+l+"px "+t+"px "+l+"px)";}}}}}}opts.cssBefore.clip=opts.cssBefore.clip||clip||"rect(0px 0px 0px 0px)";var d=opts.cssBefore.clip.match(/(\d+)/g);var t=parseInt(d[0]),r=parseInt(d[1]),b=parseInt(d[2]),l=parseInt(d[3]);opts.before.push(function(curr,next,opts){if(curr==next){return;}var $curr=$(curr),$next=$(next);$.fn.cycle.commonReset(curr,next,opts,true,true,false);opts.cssAfter.display="block";var step=1,count=parseInt((opts.speedIn/13))-1;(function f(){var tt=t?t-parseInt(step*(t/count)):0;var ll=l?l-parseInt(step*(l/count)):0;var bb=b<h?b+parseInt(step*((h-b)/count||1)):h;var rr=r<w?r+parseInt(step*((w-r)/count||1)):w;$next.css({clip:"rect("+tt+"px "+rr+"px "+bb+"px "+ll+"px)"});(step++<=count)?setTimeout(f,13):$curr.css("display","none");})();});opts.cssBefore={display:"block",opacity:1,top:0,left:0};opts.animIn={left:0};opts.animOut={left:0};};})(jQuery);
public/js/upload/jquery.easing.js ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
3
+ *
4
+ * Uses the built in easing capabilities added In jQuery 1.1
5
+ * to offer multiple easing options
6
+ *
7
+ * TERMS OF USE - jQuery Easing
8
+ *
9
+ * Open source under the BSD License.
10
+ *
11
+ * Copyright © 2008 George McGinley Smith
12
+ * All rights reserved.
13
+ *
14
+ * Redistribution and use in source and binary forms, with or without modification,
15
+ * are permitted provided that the following conditions are met:
16
+ *
17
+ * Redistributions of source code must retain the above copyright notice, this list of
18
+ * conditions and the following disclaimer.
19
+ * Redistributions in binary form must reproduce the above copyright notice, this list
20
+ * of conditions and the following disclaimer in the documentation and/or other materials
21
+ * provided with the distribution.
22
+ *
23
+ * Neither the name of the author nor the names of contributors may be used to endorse
24
+ * or promote products derived from this software without specific prior written permission.
25
+ *
26
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
27
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
31
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
35
+ *
36
+ */
37
+
38
+ // t: current time, b: begInnIng value, c: change In value, d: duration
39
+ jQuery.easing['jswing'] = jQuery.easing['swing'];
40
+
41
+ jQuery.extend( jQuery.easing,
42
+ {
43
+ def: 'easeOutQuad',
44
+ swing: function (x, t, b, c, d) {
45
+ //alert(jQuery.easing.default);
46
+ return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
47
+ },
48
+ easeInQuad: function (x, t, b, c, d) {
49
+ return c*(t/=d)*t + b;
50
+ },
51
+ easeOutQuad: function (x, t, b, c, d) {
52
+ return -c *(t/=d)*(t-2) + b;
53
+ },
54
+ easeInOutQuad: function (x, t, b, c, d) {
55
+ if ((t/=d/2) < 1) return c/2*t*t + b;
56
+ return -c/2 * ((--t)*(t-2) - 1) + b;
57
+ },
58
+ easeInCubic: function (x, t, b, c, d) {
59
+ return c*(t/=d)*t*t + b;
60
+ },
61
+ easeOutCubic: function (x, t, b, c, d) {
62
+ return c*((t=t/d-1)*t*t + 1) + b;
63
+ },
64
+ easeInOutCubic: function (x, t, b, c, d) {
65
+ if ((t/=d/2) < 1) return c/2*t*t*t + b;
66
+ return c/2*((t-=2)*t*t + 2) + b;
67
+ },
68
+ easeInQuart: function (x, t, b, c, d) {
69
+ return c*(t/=d)*t*t*t + b;
70
+ },
71
+ easeOutQuart: function (x, t, b, c, d) {
72
+ return -c * ((t=t/d-1)*t*t*t - 1) + b;
73
+ },
74
+ easeInOutQuart: function (x, t, b, c, d) {
75
+ if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
76
+ return -c/2 * ((t-=2)*t*t*t - 2) + b;
77
+ },
78
+ easeInQuint: function (x, t, b, c, d) {
79
+ return c*(t/=d)*t*t*t*t + b;
80
+ },
81
+ easeOutQuint: function (x, t, b, c, d) {
82
+ return c*((t=t/d-1)*t*t*t*t + 1) + b;
83
+ },
84
+ easeInOutQuint: function (x, t, b, c, d) {
85
+ if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
86
+ return c/2*((t-=2)*t*t*t*t + 2) + b;
87
+ },
88
+ easeInSine: function (x, t, b, c, d) {
89
+ return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
90
+ },
91
+ easeOutSine: function (x, t, b, c, d) {
92
+ return c * Math.sin(t/d * (Math.PI/2)) + b;
93
+ },
94
+ easeInOutSine: function (x, t, b, c, d) {
95
+ return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
96
+ },
97
+ easeInExpo: function (x, t, b, c, d) {
98
+ return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;
99
+ },
100
+ easeOutExpo: function (x, t, b, c, d) {
101
+ return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
102
+ },
103
+ easeInOutExpo: function (x, t, b, c, d) {
104
+ if (t==0) return b;
105
+ if (t==d) return b+c;
106
+ if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;
107
+ return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;
108
+ },
109
+ easeInCirc: function (x, t, b, c, d) {
110
+ return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
111
+ },
112
+ easeOutCirc: function (x, t, b, c, d) {
113
+ return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
114
+ },
115
+ easeInOutCirc: function (x, t, b, c, d) {
116
+ if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
117
+ return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
118
+ },
119
+ easeInElastic: function (x, t, b, c, d) {
120
+ var s=1.70158;var p=0;var a=c;
121
+ if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
122
+ if (a < Math.abs(c)) { a=c; var s=p/4; }
123
+ else var s = p/(2*Math.PI) * Math.asin (c/a);
124
+ return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
125
+ },
126
+ easeOutElastic: function (x, t, b, c, d) {
127
+ var s=1.70158;var p=0;var a=c;
128
+ if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;
129
+ if (a < Math.abs(c)) { a=c; var s=p/4; }
130
+ else var s = p/(2*Math.PI) * Math.asin (c/a);
131
+ return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
132
+ },
133
+ easeInOutElastic: function (x, t, b, c, d) {
134
+ var s=1.70158;var p=0;var a=c;
135
+ if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);
136
+ if (a < Math.abs(c)) { a=c; var s=p/4; }
137
+ else var s = p/(2*Math.PI) * Math.asin (c/a);
138
+ if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
139
+ return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
140
+ },
141
+ easeInBack: function (x, t, b, c, d, s) {
142
+ if (s == undefined) s = 1.70158;
143
+ return c*(t/=d)*t*((s+1)*t - s) + b;
144
+ },
145
+ easeOutBack: function (x, t, b, c, d, s) {
146
+ if (s == undefined) s = 1.70158;
147
+ return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
148
+ },
149
+ easeInOutBack: function (x, t, b, c, d, s) {
150
+ if (s == undefined) s = 1.70158;
151
+ if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
152
+ return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
153
+ },
154
+ easeInBounce: function (x, t, b, c, d) {
155
+ return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
156
+ },
157
+ easeOutBounce: function (x, t, b, c, d) {
158
+ if ((t/=d) < (1/2.75)) {
159
+ return c*(7.5625*t*t) + b;
160
+ } else if (t < (2/2.75)) {
161
+ return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
162
+ } else if (t < (2.5/2.75)) {
163
+ return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
164
+ } else {
165
+ return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
166
+ }
167
+ },
168
+ easeInOutBounce: function (x, t, b, c, d) {
169
+ if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
170
+ return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
171
+ }
172
+ });
173
+
174
+ /*
175
+ *
176
+ * TERMS OF USE - EASING EQUATIONS
177
+ *
178
+ * Open source under the BSD License.
179
+ *
180
+ * Copyright © 2001 Robert Penner
181
+ * All rights reserved.
182
+ *
183
+ * Redistribution and use in source and binary forms, with or without modification,
184
+ * are permitted provided that the following conditions are met:
185
+ *
186
+ * Redistributions of source code must retain the above copyright notice, this list of
187
+ * conditions and the following disclaimer.
188
+ * Redistributions in binary form must reproduce the above copyright notice, this list
189
+ * of conditions and the following disclaimer in the documentation and/or other materials
190
+ * provided with the distribution.
191
+ *
192
+ * Neither the name of the author nor the names of contributors may be used to endorse
193
+ * or promote products derived from this software without specific prior written permission.
194
+ *
195
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
196
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
197
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
198
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
199
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
200
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
201
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
202
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
203
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
204
+ *
205
+ */
{media → public/media}/CSS_JS_Toolbox_Icon.png RENAMED
Binary file
{media → public/media}/Donate_Button.png RENAMED
File without changes
{media → public/media}/accept.png RENAMED
File without changes
{media → public/media}/ajax-loader.gif RENAMED
File without changes
public/media/icons/add_code.png ADDED
Binary file
public/media/icons/delete_code.png ADDED
Binary file
public/media/icons/edit_code.png ADDED
Binary file
public/media/icons/external_link.png ADDED
Binary file
public/media/icons/insert_code.png ADDED
Binary file
{media → public/media}/icons/insert_code1.png RENAMED
File without changes
{media → public/media}/index.php RENAMED
File without changes
{media → public/media}/loading-bottom.gif RENAMED
File without changes
public/media/upload/.htaccess ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <Files *.php>
2
+ Deny from all
3
+ </Files>
public/media/upload/index.php ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php
2
+
3
+ die();
public/media/upload/latestversion.png ADDED
Binary file
{media → public/media}/warning.png RENAMED
File without changes
readme.txt CHANGED
@@ -1,83 +1,145 @@
1
  === CSS & JavaScript Toolbox ===
2
  Contributors: wipeoutmedia
3
- Author URL: http://wipeoutmedia.com/whats-new/css-javascript-toolbox/
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VMXTA3838F6A8
5
  Tags: html, css, javascript, code, custom, page, pages, post, posts, category, categories, url
6
- Requires at least: 3.0
7
- Tested up to: 3.2.1
8
- Stable tag: 0.3
9
 
10
  Easily add custom CSS and JavaScript code to individual Pages, Posts, Categories, and URLs.
11
 
12
  == Description ==
13
 
14
- If you are an avid CSS and JavaScript fan, then you will really love this nifty piece of software. Our WordPress plugin provides a great deal of flexibility by allowing you to attach custom CSS or JavaScript code to pages, posts, categories, and URLs.
15
-
16
- = Key Features =
17
-
18
- - create and save CSS or JavaScript code snippets, allowing for code reuse
19
- - give code snippets specific titles, so you can search and add them to the editor window from a drop-down list
20
- - insert button to add code to pages/posts, categories, and URLs (code is added at the cursor)
21
- - delete code from the drop-down list
22
- - add default inline and external CSS and JavaScript declarations
23
- - add extra CSS & JavaScript code block windows as needed
24
-
25
- = Instructions =
26
-
27
- [Instructions with Screenshots](http://wipeoutmedia.com/whats-new/css-javascript-toolbox/)
28
-
29
- After you have uploaded and activated the CSS & JavaScript Toolbox plugin, you will notice a new menu item appear under Settings in your Dashboard. Click 'CSS & JavaScript Toolbox' link in the left admin bar of your dashboard.
30
-
31
- Write the code, then choose what the code affects
32
- Clicking into the toolbox link from the WordPress Dashboard for the first time, you will see a CSS & JavaScript Block. Inside this block is a large editor window, and this is where you write your CSS or JavaScript code. To allow your code to run on your website, you need to specify the pages, posts, categories, or page URLs you want the code to work with. You can select multiple checkboxes and even make selections from the other tabs – just make sure you click the Save All Changes button when you are done. The three tab sections are shown in the slideshow below. Note: clicking the small box icon with the arrow in the corner will open the page for testing purposes.
33
-
34
- Adding default CSS or JavaScript declaration code
35
- If you want to add CSS or JavaScript declaration code snippets, but can never remember how they go, that’s cool, we have included these as default code snippets in the drop-down list box. Simply choose the one you want, and click the button with the green down arrow.
36
-
37
- Creating and saving your own code snippets This plugin allows you to create and save your own snippets of code so you can reuse it across additional CSS & JavaScript Blocks. To create and save your own snippets of code, simply click the button with the green cross. You will see a popup window, where you can create a title for your code, and enter the actual code in the main text area. Once you are happy with your code snippet and title, click the Save Code Template button.
38
-
39
- You can then click the drop-down list, select the code title you provided, and then click the green down arrow button to insert the code into the editor window.
40
-
41
- Adding more CSS & JavaScript Blocks We understand that one CSS & JavaScript Block is not enough. You may want to affect a different page with a whole new set of code. In this scenario, we have you covered. Look below the bottom of the block and you will find a button labelled Add New CSS/JS Block. Click that to add an entirely new CSS & JavaScript Block.
42
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  Although this plugin uses Ajax for the function calls (in other words does not refresh the webpage), please remember to save your code on a regular basis by clicking the Save All Changes button.
44
 
45
  = Thank You =
46
  We would like to take this opportunity to thank you for installing our plugin. :)
47
- We hope you enjoy using our new WordPress plugin with your development work. We do plan on developing it further with some awesomely cool updates in the near future – so stay tuned!!! If you do enjoy this plugin and not only find it useful, but appreciate the huge amount of work that has gone into creating it, you can certainly support us in a number of ways, including:
48
- - Consider donating through PayPal
49
- - Join our Newsletter mailing list for updates and news
50
- - Contact us for WordPress or logo services
51
- - Like our Facebook page
52
- - Follow us on Twitter
53
 
54
- We would also love to hear your thoughts on our plugin. How has it helped you? How did you find using it? And is there anything that could make it better? Please drop us a comment below, and thanks again for your support! Enjoy!!
 
 
 
55
 
56
  == Installation ==
57
 
58
- 1. Upload the 'css-js-toolbox' folder to the `/wp-content/plugins/` directory
59
  2. Activate the plugin through the 'Plugins' menu in WordPress
60
- 3. Click 'CSS & JavaScript Toolbox' link in the left admin bar of your dashboard
61
 
62
  == Frequently Asked Questions ==
63
- No frequently asked question at this time - stay tuned!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  == Screenshots ==
66
 
67
  1. Main CSS & JavaScript Toolbox window showing the JS/CSS Block.
68
  2. Three tab sections showing Pages (& Posts), Categories, and URL List respectively.
69
- 3. Adding default CSS or JavaScript declaration code
70
- 4. Creating and saving your own code snippets
71
- 5. Using the drop-down list box to add your own code snippets
72
- 6. Adding more CSS & JavaScript Blocks
 
 
 
 
 
73
 
74
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  = 0.3 =
76
- * This is the first and latest release
 
 
 
 
77
 
78
  == Credits ==
79
 
80
- Copyright (c) 2011, Wipeout Media.
81
 
82
  This program is free software; you can redistribute it and/or
83
  modify it under the terms of the GNU General Public License
1
  === CSS & JavaScript Toolbox ===
2
  Contributors: wipeoutmedia
3
+ Author URL: http://wipeoutmedia.com/wordpress-plugins/css-javascript-toolbox/
4
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VMXTA3838F6A8
5
  Tags: html, css, javascript, code, custom, page, pages, post, posts, category, categories, url
6
+ Requires at least: 3.2
7
+ Tested up to: 3.3.1
8
+ Stable tag: 0.8
9
 
10
  Easily add custom CSS and JavaScript code to individual Pages, Posts, Categories, and URLs.
11
 
12
  == Description ==
13
 
14
+ Add custom reusable CSS & JavaScript to pages, posts, categories & URLs.
15
+ Full code template management system.
16
+ Insert, create, save, edit and delete code templates.
17
+ Add titles to code template and blocks.
18
+ Reuse code via code templates drop-down list.
19
+ Add code to header or footer.
20
+ Add extra code blocks as needed.
21
+ Default CSS/JS declarations.
22
+ Simple and easy UI.
23
+ Page/post nav icons for page preview.
24
+ Multilingual support.
25
+ Reorder, minimise & maximise blocks.
26
+ Ability to embedded WordPress/CJToolbox Javascript files by just checking them.
27
+ jQuery Cycle and jQuery Easing included.
28
+ Ability to Backup and Restore blocks data.
29
+
30
+ [Click for full instructions with screenshots, usage hints & tips, code examples, and user feedback](http://wipeoutmedia.com/wordpress-plugins/css-javascript-toolbox)
31
+
32
+ = After Install & Activation =
33
+ After you have installed and activated the CSS & JavaScript Toolbox plugin, you will notice a new menu item appear under Settings in your Dashboard. Click the 'CSS & JavaScript Toolbox' link in the main navigation (left side of your Dashboard).
34
+
35
+ = Default code example =
36
+ First time installers will see a large editor window with a JavaScript example, that simply adds an alert box to a page of your choice. You can try it out by clicking on a page or post checkbox. Clicking the navigation icon (rectangle with arrow in corner) will open the page in a new window. When you are done exploring, simply delete the entire text content from the editor.
37
+
38
+ = Create a CSS & JavaScript Block title =
39
+ Block names are useful to keep your code blocks managed and organised. Please type a relevant name that describes what your block does, then click Save.
40
+
41
+ = Write the code, then choose what the code affects =
42
+ The large editor window is where you write your CSS or JavaScript code. To allow your code to run on your website, you need to specify the pages, posts, categories, or page URLs you want the code to work with. You can select multiple checkboxes and even make selections from the other tabs, just make sure you click the Save All Changes button when you are done.
43
+
44
+ = Insert, create, save, edit, delete your code templates =
45
+ We have created a management system so you can perform these functions with your code templates.
46
+ - down arrow icon: insert code from the drop-down list into the editor window (at cursor)
47
+ - plus sign icon: popup appears so you can add a new code template, which will be added to the drop-down list
48
+ - pen icon: popup appears allowing you edit any existing code templates
49
+ - cross icon: confirmation popup appears before deleting the code template
50
+
51
+ = Adding more CSS & JavaScript Blocks =
52
+ Look for a button labelled Add New CSS/JS Block. Click this and a popup will appear asking you to name the code block. Once the Save button is clicked, an entirely new CSS & JavaScript code block with the new name is now added. Note: CSS & JavaScript Blocks with EMPTY code will not be saved!
53
+
54
+ = Shuffle, drag, open and close CSS & JavaScript Blocks =
55
+ If you hover your mouse cursor over the title bar of the code block, the cursor should change into a four-sided arrow. This allows you to shuffle and drag the blocks around. If you click on the title bar, the code block will open and close, which may come in handy if you have many code blocks.
56
+
57
+ = Header and Footer switch =
58
+ This switch can be used to automatically add your code block to a header location or a footer location.
59
+
60
+ = Saving your work =
61
  Although this plugin uses Ajax for the function calls (in other words does not refresh the webpage), please remember to save your code on a regular basis by clicking the Save All Changes button.
62
 
63
  = Thank You =
64
  We would like to take this opportunity to thank you for installing our plugin. :)
65
+ We hope you enjoy using our new WordPress plugin with your development work. We do plan on developing it further with some really cool updates in the near future. If you enjoy this plugin and not only find it useful, but appreciate the huge amount of work that has gone into creating it, you can certainly support us in a number of ways, including:
66
+ - a small donation via [our PayPal account](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=VMXTA3838F6A8)
67
+ - provide a rating on Wordpress.org
68
+ - visit our [Wipeout Media](http://wipeoutmedia.com/wordpress-plugins/css-javascript-toolbox/) website and provide some user feedback or feature requests
69
+ - Like our [Facebook page](http://www.facebook.com/pages/Wipeout-Media/209420279099268) - we really need Likes :)
70
+ - Follow us on [Twitter](http://twitter.com/wipeoutmedia) - we really need followers too :D
71
 
72
+ Thank you very much for your support and we hope you enjoy using it as much as we enjoyed creating it.
73
+
74
+ Regards,
75
+ Wipeout Media Team
76
 
77
  == Installation ==
78
 
79
+ 1. Upload the 'css-js-toolbox' folder to the '/wp-content/plugins/' directory
80
  2. Activate the plugin through the 'Plugins' menu in WordPress
81
+ 3. Click 'CSS & JavaScript Toolbox' link in the main navigation (left side of your Dashboard).
82
 
83
  == Frequently Asked Questions ==
84
+
85
+ = Can I move the blocks around? =
86
+ Yes by hovering your mouse cursor over the code block title bar until it turns into a four-sided arrow, this allow you to move the blocks. Clicking the block title bar allows you to open and close the blocks.
87
+
88
+ = I'm using the URL List and my code is not working? =
89
+ Make sure you have copied and pasted the page, post, or category URL exactly as it appears in the address bar. For example, you may have inadvertently included an extra forward slash at the end of your URL.
90
+
91
+ = Where did my CSS & JavaScript Block I created go? =
92
+ If you have added a new CSS/JS block, created a title and clicked the Save All Changes button, and you refreshed the page when your block did not contain any code, then when the page reloads, your new 'empty' block will disappear. You must have code inside the block for it to permanently save.
93
+
94
+ = Why use the Footer switch in Location/Hook? =
95
+ Hook location feature gives you control over the location of outputting the CSS/JS code. This is useful in case overriding another Plugin CSS is required. Also sometimes its better to put your JS code in the footer to avoid slowing down your page load.
96
+
97
+ = I received a weird error, what do I do now? =
98
+ Sometimes a bug decides to rear its ugly head and when this happens, this is when we need your help. If you receive an error, if it be a PHP error, or some functionality that isn't working for whatever reason, please visit our: [Wipeout Media website and let us know](http://wipeoutmedia.com/wordpress-plugins/css-javascript-toolbox/)
99
 
100
  == Screenshots ==
101
 
102
  1. Main CSS & JavaScript Toolbox window showing the JS/CSS Block.
103
  2. Three tab sections showing Pages (& Posts), Categories, and URL List respectively.
104
+ 3. Popup window allowing you to edit the block name.
105
+ 4. Confirmation message after the Save Changes button is pressed.
106
+ 5. Popup window for writing and saving custom template CSS, JavaScript and jQuery code.
107
+ 6. Custom template code is now added and saved to the drop-down list for future use.
108
+ 7. With a press of a button, code is added to the block editor, and a page is assigned to use that code.
109
+ 8. CSS code is now styling the assigned page. Can be used for Posts, Categories and URLs too.
110
+ 9. Blocks can be ordered by click and dragging the block title bar. Single click minimises the block.
111
+ 10. Embedded WordPress or scripts that shipped out with CJToolbox Plugin by just checking them.
112
+ 11. Backup and Restore functions allow for backing up and restoring entire code blocks
113
 
114
  == Changelog ==
115
+
116
+ = 0.8 =
117
+ * Modifying template code.
118
+ * Header and Footer hooks support: Select in which hook to output CSS/JS code.
119
+ * Blocks can be reordered.
120
+ * Blocks can be named.
121
+ * New icons and improved UI.
122
+ * Multilingual support: Only English translation is shipped with this version.
123
+ * Style overriding: Blocks order allow later blocks styles to override former blocks.
124
+ * Embedded Scripts: Embedded WordPress or Scripts that shipped out with CJToolbox Plugin by just checking them.
125
+ * Backup and Restore blocks data.
126
+ * Bug Fix: New blocks not toggling unless the page is refreshed.
127
+ * Bug Fix: CSS/JS template extra slashes problem.
128
+ * Bug Fix: Block deletion issues.
129
+ * Bug Fix: Code is not applied to the URL list except the last URL.
130
+ * Bug Fix: Cannot use string offset as array error.
131
+ * Bug Fix: Invalid argument supplied foreach() error.
132
+
133
  = 0.3 =
134
+ * This is the first and latest release.
135
+
136
+ == Upgrade Notice ==
137
+
138
+ New features has been added and a few bugs fixed.
139
 
140
  == Credits ==
141
 
142
+ Copyright (c) 2012, Wipeout Media.
143
 
144
  This program is free software; you can redistribute it and/or
145
  modify it under the terms of the GNU General Public License
screenshot-1.jpg ADDED
Binary file
screenshot-1.png DELETED
Binary file
screenshot-10.jpg ADDED
Binary file
screenshot-11.jpg ADDED
Binary file
screenshot-2.jpg ADDED
Binary file
screenshot-2.png DELETED
Binary file
screenshot-3.jpg ADDED
Binary file
screenshot-3.png DELETED
Binary file
screenshot-4.jpg ADDED
Binary file
screenshot-4.png DELETED
Binary file
screenshot-5.jpg ADDED
Binary file
screenshot-5.png DELETED
Binary file
screenshot-6.jpg ADDED
Binary file
screenshot-6.png DELETED
Binary file
screenshot-7.jpg ADDED
Binary file
screenshot-8.jpg ADDED
Binary file
screenshot-9.jpg ADDED
Binary file
views/.htaccess ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <Files *>
2
+ Deny from all
3
+ </Files>
views/index.php ADDED
File without changes
views/manage.html ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="cjtoolbox-admin" class="wrap">
2
+ <div id="custom-icon" style="background: transparent url('<?php echo CJTOOLBOX_MEDIA_URL ?>/CSS_JS_Toolbox_Icon.png') no-repeat;" class="icon32"></div>
3
+ <h2><?php _e('CSS & JavaScript Toolbox', CJTOOLBOX_TEXT_DOMAIN) ?></h2>
4
+ <div id="cjtoolbox_donate">
5
+ <?php _e('Like this plugin? Please support our work', CJTOOLBOX_TEXT_DOMAIN) ?>
6
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
7
+ <input type="hidden" name="cmd" value="_s-xclick">
8
+ <input type="hidden" name="hosted_button_id" value="VMXTA3838F6A8">
9
+ <input type="image" src="<?php echo CJTOOLBOX_MEDIA_URL;?>/Donate_Button.png" border="0" name="submit" alt="<?php _e('Donate!', CJTOOLBOX_TEXT_DOMAIN) ?>">
10
+ <img alt="" border="0" src="https://www.paypalobjects.com/en_AU/i/scr/pixel.gif" width="1" height="1">
11
+ </form>
12
+ </div>
13
+ <div class="cj-save-popup" id="cj-popup-save">
14
+ <div id="cj-save-save"><?php _e('Options Updated', CJTOOLBOX_TEXT_DOMAIN) ?></div>
15
+ </div>
16
+ <div class="cj-save-popup" id="cj-popup-reset">
17
+ <div id="cj-save-reset"><?php _e('Options Reset', CJTOOLBOX_TEXT_DOMAIN) ?></div>
18
+ </div>
19
+ <div id="cj-ajax-load">
20
+ <img src="<?php echo CJTOOLBOX_MEDIA_URL; ?>/ajax-loader.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="<?php _e('Working', CJTOOLBOX_TEXT_DOMAIN) ?>..." />
21
+ </div>
22
+ <?php do_action('cjt_manage_start', $this->cjdata) ?>
23
+ <form id="cjtoolbox_form" action="admin-post.php" method="post">
24
+ <?php do_action('cjt_manage_form_start', $this->cjdata) ?>
25
+ <?php wp_nonce_field('cjtoolbox'); ?>
26
+ <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false ); ?>
27
+ <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false ); ?>
28
+ <input type="hidden" name="action" value="cjtoolbox_save" />
29
+ <input type="hidden" id="cjsecurity" name="security" value="<?php echo ($this->security_nonce = wp_create_nonce('cjtoolbox-admin'));?>" />
30
+ <input type="hidden" id="cjblock-count" name="count" value="<?php echo $count; ?>" />
31
+ <div id="poststuff" class="metabox-holder">
32
+ <div id="post-body">
33
+ <?php do_action('cjt_post_body_before_blocks') ?>
34
+ <?php do_meta_boxes($this->hook_manage, 'normal', $this->cjdata); ?>
35
+ <?php do_action('cjt_post_body_after_blocks') ?>
36
+ </div>
37
+ <br class="clear"/>
38
+ <div id="save_bar">
39
+ <a class="button-secondary" id="cjtoolbox-addblock"><?php _e('Add New CSS/JS Block', CJTOOLBOX_TEXT_DOMAIN) ?></a>
40
+ <input type="submit" value="<?php _e('Save All Changes', CJTOOLBOX_TEXT_DOMAIN) ?>" class="button-primary" name="save" />
41
+ </div>
42
+ </div>
43
+ <?php do_action('cjt_manage_form_end', $this->cjdata) ?>
44
+ </form>
45
+ <div id="cjtoolbox-tips">
46
+ <ul>
47
+ <li><?php _e('Note: CSS &amp; JavaScript Blocks with EMPTY code will not be saved!', CJTOOLBOX_TEXT_DOMAIN) ?></li>
48
+ <li><span style="font-weight:bold"><?php _e('Warning!', CJTOOLBOX_TEXT_DOMAIN) ?></span> <?php _e('Please make sure to validate added CSS &amp; JavaScript codes, the plugin doesn\'t do that for you!', CJTOOLBOX_TEXT_DOMAIN) ?></li>
49
+ </ul>
50
+ </div>
51
+ <script type="text/javascript">
52
+ var contentHash = null;
53
+ //<![CDATA[
54
+ jQuery(document).ready( function($) {
55
+ // close postboxes that should be closed
56
+ $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
57
+ // postboxes setup
58
+ postboxes.add_postbox_toggles('<?php echo $this->hook_manage; ?>');
59
+ // Create content hash for notifying use changes.
60
+ contentHash = new ContentHash({});
61
+ contentHash.generate();
62
+ });
63
+ if (Array.indexOf == undefined) { /* IE7 */
64
+ Array.prototype.indexOf = function(value) {
65
+ var index = -1;
66
+ var array = this;
67
+ jQuery.each(array, function(sIndex, sValue) {
68
+ if (sValue == value) {
69
+ index = sIndex;
70
+ return;
71
+ }
72
+ });
73
+ return index;
74
+ }
75
+ }
76
+ //]]>
77
+ </script>
78
+ <?php do_action('cjt_manage_end', $this->cjdata) ?>
79
+ </div>
views/snippets/README.txt ADDED
@@ -0,0 +1,2 @@
 
 
1
+ ajax_request_template method cannot load *.tmpl files when requested from puhlic.
2
+ ajax_request_template method can load *.html.tmpl files when requested from puhlic.
views/snippets/block.tmpl ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="cjpageblock">
2
+ <?php require CJTOOLBOX_VIEWS_SNIPPETS_PATH . '/wpobjectslist.tmpl' ?>
3
+ <div style="clear:both;"></div>
4
+ </div>
5
+ <div class="cjcontainer">
6
+ <div class="cjcodeblock">
7
+ <div class="cssblock">
8
+ <p class="cjtitle"><?php echo _e('CSS Template', CJTOOLBOX_TEXT_DOMAIN) ?> <?php $this->show_dropdown_box('css', $boxid);?></p>
9
+ <p class="cjbutton">
10
+ <a class="insert_code" title="<?php _e('Insert selected CSS Template', CJTOOLBOX_TEXT_DOMAIN) ?>" href="javascript:void('#');" onclick="return insert_code('css', '<?php echo $boxid;?>');"><?php _e('Insert Code', CJTOOLBOX_TEXT_DOMAIN) ?></a>
11
+ <a class="add_code thickbox" href="<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php?action=cjtoolbox_form&security=<?php echo $this->security_nonce ?>&type=css&width=500&height=350" title="<?php _e('Add New CSS Code Template', CJTOOLBOX_TEXT_DOMAIN) ?>"><?php _e('New', CJTOOLBOX_TEXT_DOMAIN) ?></a>
12
+ <a class="edit_code" href="javascript:void('#');" onclick="return edit_code('<?php echo $this->security_nonce ?>', <?php echo $boxid ?>, '<?php _e('Edit CSS Code Template', CJTOOLBOX_TEXT_DOMAIN) ?>', 'css', 500, 350);" title="<?php _e('Edit CSS Code Template', CJTOOLBOX_TEXT_DOMAIN) ?>"><?php _e('Edit', CJTOOLBOX_TEXT_DOMAIN) ?></a>
13
+ <a class="delete_code" title="<?php _e('Delete selected CSS Template', CJTOOLBOX_TEXT_DOMAIN) ?>" href="javascript:void('#');" onclick="return delete_code('css', '<?php echo $boxid;?>');"><?php _e('Delete Code', CJTOOLBOX_TEXT_DOMAIN) ?></a>
14
+ </p>
15
+ </div>
16
+ <div class="jsblock">
17
+ <p class="cjtitle"><?php _e('JS Template', CJTOOLBOX_TEXT_DOMAIN) ?> <?php $this->show_dropdown_box('js', $boxid);?></p>
18
+ <p class="cjbutton">
19
+ <a class="insert_code" title="<?php _e('Insert selected JavaScript Template', CJTOOLBOX_TEXT_DOMAIN) ?>" href="javascript:void('#');" onclick="return insert_code('js', '<?php echo $boxid;?>');"><?php _e('Insert Code', CJTOOLBOX_TEXT_DOMAIN) ?></a>
20
+ <a class="add_code thickbox" href="<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php?action=cjtoolbox_form&security=<?php echo $this->security_nonce ?>&type=js&width=500&height=350" title="<?php _e('Add New JavaScript Code Template', CJTOOLBOX_TEXT_DOMAIN) ?>"><?php _e('New', CJTOOLBOX_TEXT_DOMAIN) ?></a>
21
+ <a class="edit_code" href="javascript:void('#');" onclick="return edit_code('<?php echo $this->security_nonce ?>', <?php echo $boxid ?>, '<?php _e('Edit JS Code Template', CJTOOLBOX_TEXT_DOMAIN) ?>', 'js', 500, 350);" title="<?php _e('Edit JS Code Template', CJTOOLBOX_TEXT_DOMAIN) ?>"><?php _e('Edit', CJTOOLBOX_TEXT_DOMAIN) ?></a>
22
+ <a class="delete_code" title="<?php _e('Delete selected JavaScript Template', CJTOOLBOX_TEXT_DOMAIN) ?>" href="javascript:void('#');" onclick="return delete_code('js', '<?php echo $boxid;?>');"><?php _e('Delete Code', CJTOOLBOX_TEXT_DOMAIN) ?></a>
23
+ </p>
24
+ </div>
25
+ <?php do_action('cjt_block_template_panel', $boxid, $currentBlock) ?>
26
+ <div class="datablock">
27
+ <?php do_action('cjt_block_before_code', $boxid, $currentBlock) ?>
28
+ <textarea cols="100" rows="12" name="cjtoolbox[<?php echo $boxid;?>][code]" id="cjcode-<?php echo $boxid;?>"><?php echo $this->cjdata[$boxid]['code'] ;?></textarea>
29
+ <?php do_action('cjt_block_after_code', $boxid, $currentBlock) ?>
30
+ </div>
31
+ <input type="hidden" name="cjtoolbox[<?php echo $boxid;?>][block_name]" value="<?php echo $blockName ?>" />
32
+ <input type="hidden" name="cjtoolbox[<?php echo $boxid;?>][scripts]" value="<?php echo $this->getScriptsList($currentBlock) ?>" />
33
+ <input type="hidden" name="blocks[]" value="<?php echo $boxid ?>" />
34
+ <input type="hidden" name="is_new" value="<?php echo abs((int) $ajax) ?>" />
35
+ <input type="hidden" name="sync" value="<?php echo abs((int) !$ajax) ?>" />
36
+ <?php
37
+ // Meta field.
38
+ foreach ((array) $currentBlock['meta'] as $module => $values) :
39
+ foreach ($values as $metaName => $metaValue) :
40
+ $isHidden = strpos($metaName, '_');
41
+ if (($isHidden !== FALSE) && ($isHidden == 0)) {
42
+ // Fields start with underscore is private to the modules.
43
+ continue;
44
+ }
45
+ if (is_array($metaValue)) {
46
+ $metaValue = json_encode($metaValue);
47
+ }
48
+ ?>
49
+ <input type="hidden" class="meta-<?php echo $boxid ?>-<?php echo $module ?>" name="cjtoolbox[<?php echo $boxid ?>][meta][<?php echo $module ?>][<?php echo $metaName ?>]" value='<?php echo $metaValue ?>' />
50
+ <?php
51
+ endforeach;
52
+ endforeach;
53
+ ?>
54
+ <?php do_action('cjt_block_variables', $boxid, $currentBlock) ?>
55
+ </div>
56
+ </div>
57
+ <div class="extra-links-bar">
58
+ <p class="cjtitle">
59
+ <?php _e('Location', CJTOOLBOX_TEXT_DOMAIN) ?>/<?php _e('Hook', CJTOOLBOX_TEXT_DOMAIN) ?>
60
+ <select style="width:110px" name="cjtoolbox[<?php echo $boxid;?>][location]">
61
+ <?php
62
+ $location_selection = array(
63
+ 'wp_head' => __('Header', CJTOOLBOX_TEXT_DOMAIN),
64
+ 'wp_footer' => __('Footer', CJTOOLBOX_TEXT_DOMAIN),
65
+ );
66
+ foreach ($location_selection as $locationHook => $locationName) :
67
+ $blockLocation = $this->getHookLocation($currentBlock);
68
+ $selected = ( $blockLocation == $locationHook ) ? 'selected="selected"' : '';
69
+ ?>
70
+ <option value="<?php echo $locationHook ?>" <?php echo $selected ?>><?php echo $locationName ?></option>
71
+ <?php
72
+ endforeach;
73
+ ?>
74
+ </select>
75
+ </p>
76
+ <p class="embedded-scripts-link cjtitle">
77
+ <a href="javascript:void('#');" onclick="scriptsForm('<?php _e('Scripts Autoload') ?>', '<?php echo $this->security_nonce ?>', <?php echo $boxid ?>, 700, 500);" title="<?php _e('Automatically load Wordpress build-in scripts.') ?>"><?php _e('Embedded Scripts') ?></a>
78
+ </p>
79
+ <?php do_action('cjt_links_bar', $boxid, $currentBlock) ?>
80
+ </div>
81
+ <div class="deleteblock">
82
+ <p class="cjexample"><?php _e('Click for', CJTOOLBOX_TEXT_DOMAIN) ?>
83
+ <a target="_blank" href="http://wipeoutmedia.com/wordpress-plugins/css-javascript-toolbox/" title="<?php _e('Click for Hints &amp; Tips', CJTOOLBOX_TEXT_DOMAIN) ?>"><strong><?php _e('Hints', CJTOOLBOX_TEXT_DOMAIN) ?> &amp; <?php _e('Tips', CJTOOLBOX_TEXT_DOMAIN) ?></strong>
84
+ </a>
85
+ </p>
86
+ <?php if (is_array(cssJSToolbox::$premiumUpgradeTransient) && cssJSToolbox::$premiumUpgradeTransient['availability']) : ?>
87
+ <p class="upgradeLink">
88
+ <?php _e('Upgrade to') ?>
89
+ <a target="_blank" href="<?php echo cssJSToolbox::$premiumUpgradeTransient['upgradeLink'] ?>"><img src="<?php echo cssJSToolbox::$premiumUpgradeTransient['imageURL'] ?>" /><?php _e('CSS & Javascript Toolbox') ?> <?php echo cssJSToolbox::$premiumUpgradeTransient['version'] ?>
90
+ </a>
91
+ </p>
92
+ <?php endif; ?>
93
+ <a class="button-secondary save_changes_button" href="javascript:void('#');" onclick="return block_saveAllChanges();" style="<?php echo ((($blocksCount > 1) || ($ajax)) ? '' : 'display:none') ?>"><?php _e('Save Changes', CJTOOLBOX_TEXT_DOMAIN) ?></a>
94
+ <a class="button-secondary delete_block_button" href="javascript:void('#');" onclick="return delete_block('<?php echo ($boxid + 1);?>');" style="<?php echo ((($blocksCount > 1) || ($ajax)) ? '' : 'display:none') ?>"><?php _e('Delete This Block', CJTOOLBOX_TEXT_DOMAIN) ?></a>
95
+ <a class="button-secondary edit_block_button" href="javascript:void('#');" onclick="return editBlockNameForm('<?php _e('Edit Block Name', CJTOOLBOX_TEXT_DOMAIN) ?>', '<?php echo $this->security_nonce ?>', <?php echo $boxid ?>, 331, 211);" title="<?php _e('Edit Block Name', CJTOOLBOX_TEXT_DOMAIN) ?>"><?php _e('Edit Block Name', CJTOOLBOX_TEXT_DOMAIN) ?></a>
96
+ <div style="clear:both;"></div>
97
+ </div>
views/snippets/blockname.html.tmpl ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <div id="cjtoolbox_popup">
3
+ <form id="cjtoolbox_block_name">
4
+ <input type="hidden" name="block_id" value="<?php echo $_GET['block_id'] ?>" />
5
+ <p><label><?php _e('Block Name', CJTOOLBOX_TEXT_DOMAIN) ?><br /><input type="text" id="block_name" name="block_name" value="<?php echo $_GET['block_name'] ?>" style="width:300px" /></label></p>
6
+ <input type="submit" name="submit" value="Save" />
7
+ <?php if ($_GET['isNew']) : ?>
8
+ <input type="button" value="<?php _e('Cancel', CJTOOLBOX_TEXT_DOMAIN) ?>" onclick="return closeBlockNameForm(<?php echo $_GET['block_id'] ?>, <?php echo $_GET['isNew'] ?>);" />
9
+ <?php else : ?>
10
+ <input type="button" value="<?php _e('Close', CJTOOLBOX_TEXT_DOMAIN) ?>" onclick="return closeBlockNameForm(<?php echo $_GET['block_id'] ?>, <?php echo $_GET['isNew'] ?>);" />
11
+ <?php endif; ?>
12
+ <img style="display:none;" src="<?php echo CJTOOLBOX_MEDIA_URL ?>/loading-bottom.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="<?php _e('Working', CJTOOLBOX_TEXT_DOMAIN) ?>..." />
13
+ </form>
14
+ <p class="popup-note">
15
+ <?php _e('Block names are useful to keep your code blocks managed and organised.') ?>
16
+ <?php _e('Please type a relevant name that describes what your block does, then click Save.') ?>
17
+ </p>
18
+ <script type="text/javascript">
19
+ jQuery('#TB_window #TB_closeWindowButton').click(function(){
20
+ closeBlockNameForm(<?php echo $_GET['block_id'] ?>, <?php echo $_GET['isNew'] ?>);
21
+ });
22
+ </script>
23
+ </div>
views/snippets/newblock.html.tmpl ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <div id="cjtoolbox-<?php echo $count+1; ?>" class="postbox">
2
+ <div class="handlediv" title="Click to toggle"><br /></div><h3 class='hndle'><span><?php echo sprintf(__('CSS & JavaScript Block: %s', CJTOOLBOX_TEXT_DOMAIN), $count+1) ?></span></h3>
3
+ <div class="inside">
4
+ <?php $this->cjtoolbox_unit('', $args, true); ?>
5
+ </div>
6
+ </div>
views/snippets/newcode.html.tmpl ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="cjtoolbox_popup">
2
+ <form id="cjtoolbox_newcode" action="admin-post.php" method="post">
3
+ <input id="new_type" type="hidden" name="new_type" value="<?php echo $template['type'];?>" />
4
+ <input id="new_id" type="hidden" name="id" value="<?php echo $template['id'];?>" />
5
+ <input id="new_security" type="hidden" name="security" value="<?php echo wp_create_nonce('cjtoolbox-popup');?>" />
6
+ <input type="hidden" id="content_hash" value="" />
7
+ <script type="text/javascript">
8
+ jQuery('#cjtoolbox_newcode #content_hash').val(getCodeTemplateContentHash());
9
+ </script>
10
+ <fieldset>
11
+ <ul>
12
+ <li>
13
+ <label class="field-title" for="new_title"><?php _e('Title', CJTOOLBOX_TEXT_DOMAIN) ?></label><input type="text" id="new_title" name="new_title" value="<?php echo $template['title'] ?>" style="width:324px" />
14
+ </li>
15
+ <li style="vertical-align:top">
16
+ <label class="field-title" for="new_code"></label><textarea id="new_code" name="new_code"><?php echo $template['code'] ?></textarea>
17
+ </li>
18
+ <li>
19
+ <label class="field-title" style="width:95px"></label>
20
+ <input type="submit" name="submit" value="<?php _e('Save Changes', CJTOOLBOX_TEXT_DOMAIN) ?>" />
21
+ <?php if ($template['id']) : ?>
22
+ <input type="button" value="<?php _e('Close', CJTOOLBOX_TEXT_DOMAIN) ?>" onclick="tb_remove();" />
23
+ <?php else : ?>
24
+ <input type="button" value="<?php _e('Cancel', CJTOOLBOX_TEXT_DOMAIN) ?>" onclick="tb_remove();" />
25
+ <?php endif; ?>
26
+ </li>
27
+ </ul>
28
+ </fieldset>
29
+ <img style="display:none;" src="<?php echo CJTOOLBOX_MEDIA_URL ?>/loading-bottom.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="<?php _e('Working', CJTOOLBOX_TEXT_DOMAIN) ?>..." />
30
+ </form>
31
+ </div>
views/snippets/scripts.html.tmpl ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="cjtoolbox_popup" class="cjt-block-scripts">
2
+ <form id="cjtoolbox_embedded_scripts">
3
+ <input type="hidden" name="block_id" value="<?php echo $_GET['block_id'] ?>" />
4
+ <ul>
5
+ <?php
6
+ // Get Wordpress scripts.
7
+ $wp_scripts = new WP_Scripts();
8
+ wp_default_scripts($wp_scripts);
9
+ // Register additional script that shipped with the Plugin.
10
+ $this->registerScripts($wp_scripts);
11
+ // Block selected scripts.
12
+ $selections = explode(',', (string) $_GET['selections']);
13
+ // Sort scripts.
14
+ $scripts = $wp_scripts->registered;
15
+ ksort($scripts);
16
+ foreach ($scripts as $handle => $script) :
17
+ // Gen friendly name from handle name.
18
+ $handleFriendlyName = str_replace(array('-', '_'), ' ', $handle);
19
+ $handleFriendlyName = ucfirst($handleFriendlyName);
20
+ $checkboxId = "cjt-script-{$handle}";
21
+ if (in_array($handle, $selections)) {
22
+ $checked = 'checked="checked"';
23
+ $labelStyle = 'class="marked-text"';
24
+ } else{
25
+ $labelStyle = $checked = '';
26
+ }
27
+ ?>
28
+ <li><input type="checkbox" name="cjt-scripts[]" id="<?php echo $checkboxId ?>" value="<?php echo $handle ?>" <?php echo $checked ?>/><label title="<?php echo "{$handleFriendlyName} ({$script->ver})" ?>" <?php echo $labelStyle ?> for="<? echo $checkboxId ?>"> <?php echo $handleFriendlyName ?></label></li>
29
+ <?php
30
+ endforeach;
31
+ ?>
32
+ </ul>
33
+ <input type="submit" name="submit" value="Save" />
34
+ <input type="button" value="<?php _e('Close', CJTOOLBOX_TEXT_DOMAIN) ?>" onclick="tb_remove();" />
35
+ <img style="display:none;" src="<?php echo CJTOOLBOX_MEDIA_URL ?>/loading-bottom.gif" class="ajax-loading-img ajax-loading-img-bottom" alt="<?php _e('Working', CJTOOLBOX_TEXT_DOMAIN) ?>..." />
36
+ </form>
37
+ </div>
views/snippets/wpobjectslist.tmpl ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $pages = $this->cjdata[$boxid]['page'];
3
+ $categories = $this->cjdata[$boxid]['category'];
4
+ ?>
5
+ <div id="tabs-<?php echo $boxid;?>">
6
+ <ul>
7
+ <li><a href="#tabs-<?php echo $boxid;?>-1"><?php _e('Pages', CJTOOLBOX_TEXT_DOMAIN) ?></a></li>
8
+ <li><a href="#tabs-<?php echo $boxid;?>-2"><?php _e('Categories', CJTOOLBOX_TEXT_DOMAIN) ?></a></li>
9
+ <li><a href="#tabs-<?php echo $boxid;?>-3"><?php _e('URL List', CJTOOLBOX_TEXT_DOMAIN) ?></a></li>
10
+ </ul>
11
+ <div id="tabs-<?php echo $boxid;?>-1">
12
+ <p><?php _e('Add this CSS/JS code to ?', CJTOOLBOX_TEXT_DOMAIN) ?></p>
13
+ <ul class="pagelist">
14
+ <li>
15
+ <label>
16
+ <input type="checkbox" name="cjtoolbox[<?php echo $boxid;?>][page][]" value="frontpage" <?php echo (is_array($pages) && in_array('frontpage', $pages)) ? 'checked="checked"' : ''; ?> /> <?php _e('Front Page', CJTOOLBOX_TEXT_DOMAIN) ?>
17
+ </label>
18
+ <a class="l_ext" target="_blank" href="<?php bloginfo('url');?>"></a></li>
19
+ <li>
20
+ <label>
21
+ <input type="checkbox" name="cjtoolbox[<?php echo $boxid;?>][page][]" value="allposts" <?php echo (is_array($pages) && in_array('allposts', $pages)) ? 'checked="checked"' : ''; ?> /> <?php _e('All Posts', CJTOOLBOX_TEXT_DOMAIN) ?>
22
+ </label>
23
+ </li>
24
+ <li>
25
+ <label>
26
+ <input type="checkbox" name="cjtoolbox[<?php echo $boxid;?>][page][]" value="allpages" <?php echo (is_array($pages) && in_array('allpages', $pages)) ? 'checked="checked"' : ''; ?> /> <?php _e('All Pages', CJTOOLBOX_TEXT_DOMAIN) ?>
27
+ </label>
28
+ </li>
29
+ <?php $this->show_pages_with_checkbox($boxid, $pages); ?>
30
+ </ul>
31
+ </div>
32
+ <div id="tabs-<?php echo $boxid;?>-2">
33
+ <p><?php _e('Add this CSS/JS code to category page?', CJTOOLBOX_TEXT_DOMAIN) ?></p>
34
+ <ul class="pagelist">
35
+ <?php $this->show_taxonomy_with_checkbox($boxid, $categories); ?>
36
+ </ul>
37
+ </div>
38
+ <div id="tabs-<?php echo $boxid;?>-3" class="linklist">
39
+ <p><?php _e('Add one URL per line (include http://)', CJTOOLBOX_TEXT_DOMAIN) ?></p>
40
+ <textarea cols="31" rows="9" name="cjtoolbox[<?php echo $boxid;?>][links]" id="cjcode-links-<?php echo $boxid;?>"><?php echo $this->cjdata[$boxid]['links'] ;?></textarea>
41
+ </div>
42
+ </div>
43
+ <script type="text/javascript">
44
+ jQuery(function() {
45
+ jQuery("#tabs-<?php echo $boxid;?>").tabs();
46
+ });
47
+ </script>