This repository has been archived by the owner on Feb 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
axl_sc_standard.module
executable file
·667 lines (609 loc) · 18 KB
/
axl_sc_standard.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
<?php
/**
* @file
* Axelerant Standard shortcodes module.
*/
/**
* Implements hook_js_alter().
*
* Replace the shortcode_wysiwwyg.js with our custom version
*/
function axl_sc_standard_js_alter(&$javascript) {
$path = drupal_get_path('module', 'shortcode_wysiwyg') . '/plugins/shortcode_wysiwyg/shortcode_wysiwyg.js';
if (isset($javascript[$path])) {
$javascript[$path]['data'] = drupal_get_path('module', 'axl_sc_standard') . '/shortcode_wysiwyg.js';
}
}
/**
* Implements hook_filter_info().
*/
function axl_sc_standard_filter_info() {
$filters['axl_sc_standard_text_preprocess'] = array(
'title' => t('Shortcodes - Preprocess text'),
'description' => t('Remove spurious characters from inside shortcode tags. Run before shortcode filter.'),
'process callback' => '_axl_sc_standard_preprocess_text',
);
$filters['axl_sc_standard_no_cache'] = array(
'title' => t('Shortcodes - Dynamic content'),
'description' => t('If using embedded content that might change use this filter to turn off text caching.'),
'process callback' => '_axl_sc_standard_no_cache',
'cache' => FALSE,
);
return $filters;
}
/**
* Implements hook_filter_info_alter().
*/
function axl_sc_standard_filter_info_alter(&$info) {
$info['shortcode_text_corrector']['description'] = t('Correct html after processing shortcode. Enable only if a wysiwyg editor is used.');
}
/**
* Implements hook_shortcode_info().
*/
function axl_sc_standard_shortcode_info() {
$shortcodes['code'] = array(
'title' => t('Code'),
'description' => t('Code.'),
'process callback' => 'axl_sc_standard_code',
'tips callback' => 'axl_sc_standard_code_tips',
'default settings' => array(),
'attributes callback' => 'axl_sc_standard_code_attributes',
);
$shortcodes['col'] = array(
'title' => t('Columns'),
'description' => t('Simple columns in content'),
'process callback' => 'axl_sc_standard_columns',
'tips callback' => 'axl_sc_standard_columns_tips',
'default settings' => array(),
'attributes callback' => 'axl_sc_standard_columns_attributes',
);
$shortcodes['fn'] = array(
'title' => t('Footnote'),
'description' => t('Creates a footnote.'),
'process callback' => 'axl_sc_standard_footnote',
'tips callback' => 'axl_sc_standard_footnote_tips',
'default settings' => array(),
'attributes callback' => 'axl_sc_standard_footnote_attributes',
);
$shortcodes['highlight'] = array(
'title' => t('Highlight'),
'description' => t('highlight an inline text'),
'process callback' => 'axl_sc_standard_highlight',
'tips callback' => 'axl_sc_standard_highlight_tips',
'default settings' => array(),
'attributes callback' => 'axl_sc_standard_highlight_attributes',
);
$shortcodes['infobox'] = array(
'title' => t('Info Box'),
'description' => t('Creates an Info Box'),
'process callback' => 'axl_sc_standard_infobox',
'tips callback' => 'axl_sc_standard_infobox_tips',
'default settings' => array(),
'attributes callback' => 'axl_sc_standard_infobox_attributes',
);
$shortcodes['notification'] = array(
'title' => t('Notification'),
'description' => t('Creates a Notification'),
'process callback' => 'axl_sc_standard_notification',
'tips callback' => 'axl_sc_standard_notification_tips',
'default settings' => array(),
'attributes callback' => 'axl_sc_standard_notification_attributes',
);
$shortcodes['teaser'] = array(
'title' => t('Teaser'),
'description' => t('Creates an Teaser'),
'process callback' => 'axl_sc_standard_teaser',
'tips callback' => 'axl_sc_standard_teaser_tips',
'default settings' => array(),
'attributes callback' => 'axl_sc_standard_teaser_attributes',
);
$shortcodes['icon'] = array(
'title' => t('Icon'),
'description' => t('Creates an icon.'),
'process callback' => 'axl_sc_standard_icon',
'tips callback' => 'axl_sc_standard_icon_tips',
'default settings' => array(),
'attributes callback' => 'axl_sc_standard_icon_attributes',
);
$shortcodes['center'] = array(
'title' => t('Center'),
'description' => t('Center any text or images.'),
'process callback' => 'axl_sc_standard_center',
'tips callback' => 'axl_sc_standard_center_tips',
'default settings' => array(),
'attributes callback' => 'axl_sc_standard_center_attributes',
);
return $shortcodes;
}
/**
* Implements hook_theme().
*/
function axl_sc_standard_theme() {
return array(
'axl_sc_standard_footnote' => array(
'variables' => array('text' => '', 'class' => ''),
),
'axl_sc_standard_infobox' => array(
'variables' => array('title' => NULL, 'text' => NULL, 'class' => NULL),
),
'axl_sc_standard_notification' => array(
'variables' => array('text' => '', 'class' => ''),
),
'axl_sc_standard_teaser' => array(
'variables' => array('text' => '', 'class' => ''),
),
);
}
/*============================================================================================*/
/* Code
/*============================================================================================*/
/**
* Process [code] shortcode.
*/
function axl_sc_standard_code($attrs, $text) {
extract(shortcode_attrs(array(
'class' => '',
), $attrs));
return '<pre>' . $text . '</pre>';
}
/**
* Tips for [code] shortcode.
*/
function axl_sc_standard_code_tips($format, $long) {
$output = '<strong>[code]</strong>Content Here<strong>[/code]</strong>';
return $output;
}
/*============================================================================================*/
/* Columns
/*============================================================================================*/
/**
* Process [col] shortcode.
*/
function axl_sc_standard_columns($attrs, $content = NULL) {
extract(shortcode_attrs(array(
'width' => '',
'align' => '',
'last' => '',
'clear' => '',
'class' => '',
), $attrs));
$classes = array();
if ($last) {
$classes[] = 'col-last';
}
if ($width) {
$classes[] = 'col-' . $width;
}
if ($align == 'right') {
$classes[] = 'float-right';
}
if ($align == 'center') {
$classes[] = 'align-center';
}
if ($clear) {
$classes[] = 'clear-both';
}
$classes = trim(implode(' ', $classes));
return '<div class="' . $classes . '">' . $content . '</div>';
}
/**
* Tips for [col] shortcode.
*/
function axl_sc_standard_columns_tips($format, $long) {
$output = '<strong>[col width="1-2"]</strong>Content Here<strong>[/col][col width="1-2" last="1"]</strong>Content here<strong>[/col]</strong>';
return $output;
}
/**
* Attributes for [col] shortcode.
*/
function axl_sc_standard_columns_attributes($form, $form_state) {
$form['width'] = array(
'#type' => 'select',
'#title' => t('Column width'),
'#options' => array(
'' => t('Auto'),
'1-8' => t('1/8'),
'1-7' => t('1/7'),
'1-6' => t('1/6'),
'1-5' => t('1/5'),
'1-4' => t('1/4'),
'1-3' => t('1/3'),
'1-2' => t('1/2'),
'2-3' => t('2/3'),
'3-4' => t('3/4'),
'2-5' => t('2/5'),
'3-5' => t('3/5'),
'4-5' => t('4/5'),
'5-6' => t('5/6'),
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'col'),
),
),
);
$form['align'] = array(
'#type' => 'select',
'#title' => t('Alignment of element'),
'#options' => array(
'' => t('Left'),
'right' => t('Right'),
'center' => t('Center'),
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'col'),
),
),
);
$form['clear'] = array(
'#type' => 'select',
'#title' => t('Float clearing'),
'#options' => array(
'' => t('None'),
'clear-both' => t('Clear both'),
'clear-left' => t('Clear left'),
'clear-right' => t('Clear right'),
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'col'),
),
),
);
$form['last'] = array(
'#type' => 'select',
'#title' => t('Last column in row'),
'#description' => t('If this columns is last in a row you need to check this'),
'#options' => array(
'' => t('No'),
1 => t('Last in row'),
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'col'),
),
),
);
return $form;
}
/*============================================================================================*/
/* Footnote
/*============================================================================================*/
/**
* Process [fn] shortcode.
*/
function axl_sc_standard_footnote($attrs, $text) {
extract(shortcode_attrs(array(
'class' => 'footnote',
), $attrs));
return theme('axl_sc_standard_footnote', array('text' => $text, 'class' => $class));
}
/**
* Tips for [fn] shortcode.
*/
function axl_sc_standard_footnote_tips($format, $long) {
$output = '<strong>[fn]</strong>Content Here<strong>[/fn]</strong>';
return $output;
}
/**
* Theme callback for [fn] shortcode.
*/
function theme_axl_sc_standard_footnote($vars) {
return '<div class="' . $vars['class'] . '" >' . $vars['text'] . '</div>';
}
/*============================================================================================*/
/* Highlight
/*============================================================================================*/
/**
* Process [highlight] shortcode.
*/
function axl_sc_standard_highlight($attrs, $text) {
extract(shortcode_attrs(array(
'color' => '',
'class' => 'highlight',
), $attrs));
$class = shortcode_add_class($class, $color);
return '<span class="' . $class . '">' . $text . '</span>';
}
/**
* Tips for [highlight] shortcode.
*/
function axl_sc_standard_highlight_tips($format, $long) {
$output = '<strong>[highlight color="gold"]</strong>Content Here<strong>[/highlight]</strong>';
return $output;
}
/**
* Attributes for [highlight] shortcode.
*/
function axl_sc_standard_highlight_attributes($form, $form_state) {
$form['color'] = array(
'#type' => 'select',
'#title' => t('Highlight Color'),
'#options' => array(
'' => t('Blue'),
'gold' => t('Gold'),
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'highlight'),
),
),
);
return $form;
}
/*============================================================================================*/
/* Info Box
/*============================================================================================*/
/**
* Process [infobox] shortcode.
*/
function axl_sc_standard_infobox($attrs, $text) {
extract(shortcode_attrs(array(
'title' => '',
'class' => 'infobox',
), $attrs));
return theme('axl_sc_standard_infobox', array(
'title' => $title,
'text' => $text,
'class' => $class,
));
}
/**
* Tips for [infobox] shortcode.
*/
function axl_sc_standard_infobox_tips($format, $long) {
$output = '<strong>[infobox title="Info Box Title Here"]</strong>Content Here<strong>[/infobox]</strong>';
return $output;
}
/**
* Theme callback for [infobox] shortcode.
*/
function theme_axl_sc_standard_infobox($vars) {
$title = '';
if (isset($vars['title']) && $vars['title'] != '') {
$title = "<h3>" . $vars['title'] . "</h3>";
}
return '<div class="' . $vars['class'] . '" >' . $title . $vars['text'] . '</div>';
}
/**
* Attributes for [infobox] shortcode.
*/
function axl_sc_standard_infobox_attributes($form, $form_state) {
$form['sc_title'] = array(
'#type' => 'textfield',
'#title' => t('Title'),
'#default_value' => t('Info Box Title Here'),
'#size' => 30,
'#maxlength' => 60,
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'infobox'),
),
),
);
return $form;
}
/*============================================================================================*/
/* Notification
/*============================================================================================*/
/**
* Process [notification] shortcode.
*/
function axl_sc_standard_notification($attrs, $text) {
extract(shortcode_attrs(array(
'bold' => '',
'color' => '',
'class' => '',
), $attrs));
$class = shortcode_add_class($class, $color);
return theme('axl_sc_standard_notification', array(
'bold' => $bold,
'text' => $text,
'class' => $class,
));
}
/**
* Tips for [notification] shortcode.
*/
function axl_sc_standard_notification_tips($format, $long) {
$output = '<strong>[notification bold="Bold Text Here" color="notification-red"]</strong>Content Here<strong>[/notification]</strong>';
return $output;
}
/**
* Theme callback for [notification] shortcode.
*/
function theme_axl_sc_standard_notification($vars) {
return '<div class="' . $vars['class'] . '" ><p><strong>' . $vars['bold'] . '</strong>' . $vars['text'] . '</p></div>';
}
/**
* Attributes for [notification] shortcode.
*/
function axl_sc_standard_notification_attributes($form, $form_state) {
$form['bold'] = array(
'#type' => 'textfield',
'#title' => t('Bold Text'),
'#size' => 30,
'#maxlength' => 30,
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'notification'),
),
),
);
$form['color'] = array(
'#type' => 'select',
'#title' => t('Color'),
'#options' => array(
'notification-red' => t('Red'),
'notification-yellow' => t('Yellow'),
'notification-blue' => t('Blue'),
'notification-green' => t('Green'),
),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'notification'),
),
),
);
return $form;
}
/*============================================================================================*/
/* Teaser
/*============================================================================================*/
/**
* Process [teaser] shortcode.
*/
function axl_sc_standard_teaser($attrs, $text) {
extract(shortcode_attrs(array(
'title' => '',
'class' => 'teaser',
), $attrs));
return theme('axl_sc_standard_teaser', array(
'text' => $text,
'class' => $class,
));
}
/**
* Tips for [teaser] shortcode.
*/
function axl_sc_standard_teaser_tips($format, $long) {
$output = '<strong>[teaser]</strong>Content Here<strong>[/teaser]</strong>';
return $output;
}
/**
* Theme callback for [teaser] shortcode.
*/
function theme_axl_sc_standard_teaser($vars) {
return '<p class="' . $vars['class'] . '" >' . $vars['text'] . '</p>';
}
/*============================================================================================*/
/* Icons
/*============================================================================================*/
/**
* Process [icon] shortcode.
*/
function axl_sc_standard_icon($attrs) {
extract(shortcode_attrs(array(
'name' => '',
'icon_name' => '',
'size' => '1',
), $attrs));
$class = '';
$class = shortcode_add_class($class, 'fa');
$class = shortcode_add_class($class, $name);
$class = shortcode_add_class($class, $icon_name);
if (is_numeric($size)) {
$size = floor($size);
switch ($size) {
default:
$size_class = 'fa-1g';
break;
case 2:
case 3:
case 4:
case 5:
$size_class = 'fa-' . $size . 'x';
break;
}
}
$class = shortcode_add_class($class, $size_class);
return "<i class='" . $class . "'></i>";
}
/**
* Tips for [icon] shortcode.
*/
function axl_sc_standard_icon_tips($format, $long) {
$output = '<strong>[icon name="Icon name" size="3" /]</strong>';
return $output;
}
/**
* Theme callback for [icon] shortcode.
*/
function theme_shortcode_icon($vars) {
if (is_numeric($vars['size'])) {
$size_class = 'fa-' . $vars['size'] . 'x';
}
return "<i class='" . implode(' ', $classes) . "'></i>";
}
/**
* Attributes for [icon] shortcode.
*/
function axl_sc_standard_icon_attributes($form, $form_state) {
$path = path_to_theme() . '/font-awesome/css/font-awesome.css';
$path = drupal_realpath($path);
$css = file_get_contents($path);
$options = array();
if (preg_match_all("/\.(fa-[a-zA-Z0-9\-]+)\:before/", $css, $matches) > 0) {
foreach ($matches[1] as $option) {
$options[$option] = $option;
}
asort($options);
}
$form['icon_name'] = array(
'#type' => 'select',
'#title' => t('Icon Name'),
'#options' => $options,
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'icon'),
),
),
);
$form['size'] = array(
'#type' => 'select',
'#title' => t('Icon Size'),
'#options' => drupal_map_assoc(array(1, 2, 3, 4, 5)),
'#states' => array(
'visible' => array(
':input[name="shortcode"]' => array('value' => 'icon'),
),
),
);
return $form;
}
/*============================================================================================*/
/* Center
/*============================================================================================*/
/**
* Process [center] shortcode.
*/
function axl_sc_standard_center($attrs, $text) {
extract(shortcode_attrs(array(
'name' => '',
), $attrs));
return '<div class="sc-center">' . $text . '</div>';
}
/**
* Tips for [center] shortcode.
*/
function axl_sc_standard_center_tips($format, $long) {
$output = '<strong>[center]</strong>Content to align<strong>[/center]</strong>';
return $output;
}
/**
* Remove any from source before processing shortcodes.
*/
function _axl_sc_standard_preprocess_text($text, $filter) {
return preg_replace_callback('|\[([^\]]+)\]|is',
function ($matches) {
// Replace characters with [] tag.
return str_replace(array(
' ',
'"/]',
"'/]",
), array(
' ',
'" /]',
"' /]",
), $matches[0]);
},
$text
);
}
/**
* Dummy filter that just turns off cache.
*/
function _axl_sc_standard_no_cache($text, $filter) {
return $text;
}