Shortcodes by Angie Makes - Version 3.34

Version Description

Download this release

Release Info

Developer cbaldelomar
Plugin Icon wp plugin Shortcodes by Angie Makes
Version 3.34
Comparing to
See all releases

Code changes from version 3.33 to 3.34

README.md CHANGED
@@ -106,6 +106,10 @@ See our help article on [how to manually upload a plugin](http://knowledgebase.a
106
 
107
  ## Changelog ##
108
 
 
 
 
 
109
  ### Version 3.33 ###
110
 
111
  * Updated WPC Settings Framework to 1.0.7
106
 
107
  ## Changelog ##
108
 
109
+ ### Version 3.34 ###
110
+
111
+ * added ability to add custom template shortcodes
112
+
113
  ### Version 3.33 ###
114
 
115
  * Updated WPC Settings Framework to 1.0.7
admin/assets/js/shortcodes-tinymce-4.js CHANGED
@@ -10,7 +10,7 @@
10
 
11
  editor.addButton('wpc_shortcodes_button', function() {
12
 
13
- return {
14
  title: "",
15
  text: "[ ]",
16
  image: url + "/images/shortcodes.png",
@@ -366,14 +366,49 @@
366
  },
367
  ]
368
  },
 
 
 
 
 
369
  {
370
- text: "[edit_selection]",
371
- onclick: function(){
372
- wcShortcodes( mceSelected, editor );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
373
  }
374
- },
375
- ]
376
  }
 
 
 
 
 
 
 
 
 
 
 
 
377
  });
378
  };
379
 
10
 
11
  editor.addButton('wpc_shortcodes_button', function() {
12
 
13
+ var dropdown = {
14
  title: "",
15
  text: "[ ]",
16
  image: url + "/images/shortcodes.png",
366
  },
367
  ]
368
  },
369
+ ]
370
+ };
371
+
372
+ if ( typeof wpc_shortcodes_template_buttons == "object") {
373
+ var size = dropdown.menu.push(
374
  {
375
+ text: "Templates",
376
+ menu: [],
377
+ }
378
+ );
379
+ var index = size - 1;
380
+ for ( var property in wpc_shortcodes_template_buttons ) {
381
+ /* http://stackoverflow.com/questions/12718284/javascript-onclick-shows-last-element-of-array-with-for-loop */
382
+ /* http://conceptf1.blogspot.com/2013/11/javascript-closures.html */
383
+ (function(property) {
384
+ if ( wpc_shortcodes_template_buttons.hasOwnProperty( property ) ) {
385
+ if ( 'title' in wpc_shortcodes_template_buttons[property] && 'content' in wpc_shortcodes_template_buttons[property] ) {
386
+ dropdown.menu[index].menu.push(
387
+ {
388
+ text: wpc_shortcodes_template_buttons[property]['title'],
389
+ onclick: function(){
390
+ editor.setContent('');
391
+ editor.insertContent( wpc_shortcodes_template_buttons[property]['content'] );
392
+ }
393
+ }
394
+ );
395
+ }
396
  }
397
+ })(property);
398
+ }
399
  }
400
+
401
+ dropdown.menu.push(
402
+ {
403
+ text: "[edit_selection]",
404
+ onclick: function(){
405
+ wcShortcodes( mceSelected, editor );
406
+ }
407
+ }
408
+ );
409
+
410
+
411
+ return dropdown;
412
  });
413
  };
414
 
admin/class-tinymce-buttons.php CHANGED
@@ -14,7 +14,7 @@ class WPC_Shortcodes_TinyMCE_Buttons {
14
 
15
  private function __construct() {
16
  add_action( 'admin_head', array( &$this,'init' ) );
17
- // add_action( 'admin_head', array( &$this, 'localize_script' ) );
18
  }
19
 
20
  public function init() {
@@ -27,13 +27,101 @@ class WPC_Shortcodes_TinyMCE_Buttons {
27
  }
28
  }
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  public function localize_script() {
31
- global $wc_shortcodes_theme_support;
 
 
 
 
 
 
32
 
33
  ?>
34
- <script type="text/javascript">
35
- var wpc_shortcodes = <?php echo json_encode( $wc_shortcodes_theme_support ); ?>;
36
- </script>
 
 
37
  <?php
38
  }
39
 
14
 
15
  private function __construct() {
16
  add_action( 'admin_head', array( &$this,'init' ) );
17
+ add_action( 'admin_head', array( &$this, 'localize_script' ) );
18
  }
19
 
20
  public function init() {
27
  }
28
  }
29
 
30
+ function clean_content( $content ) {
31
+ $p = array();
32
+
33
+ $first = true;
34
+ $i = 0;
35
+
36
+ $content = str_replace( "\n\n\n", "\n\n", $content );
37
+ $content = preg_replace( "/(\<\/[a-zA-Z0-9]+\>)\s*\n+/", "\\1\n\n", $content );
38
+ $content = explode( "\n\n", $content );
39
+ $size = sizeof( $content ) - 1;
40
+
41
+ foreach ( $content as $line) {
42
+ $line = trim( $line );
43
+ if ( $line ) {
44
+ if ( $first ) {
45
+ $p[] = $line;
46
+ }
47
+ else if ( isset( $line[0] ) && ( '<' == $line[0] ) ) {
48
+ $p[] = $line;
49
+ }
50
+ else if ( $i >= $size ) {
51
+ $p[] = $line;
52
+ }
53
+ else {
54
+ $p[] = '<p>' . $line . '</p>';
55
+ }
56
+
57
+ $first = false;
58
+ }
59
+ $i++;
60
+ }
61
+ $content = implode( '', $p );
62
+ $content = str_replace( "\n", "<br />", $content );
63
+
64
+ return $content;
65
+ }
66
+
67
+ function clean_title( $filename ) {
68
+ $title = basename( $filename, '.txt' );
69
+ $title = preg_replace( '/^\d+/', '', $title );
70
+ $title = str_replace( '-', ' ', $title );
71
+ $title = str_replace( '_', ' ', $title );
72
+ $title = trim( $title );
73
+ $title = ucwords( $title );
74
+
75
+ return $title;
76
+ }
77
+ function find_templates( $template_path ) {
78
+ if ( empty( $template_path ) ) {
79
+ return null;
80
+ }
81
+
82
+ if ( ! is_string( $template_path ) ) {
83
+ return null;
84
+ }
85
+
86
+ $templates = array();
87
+ $i = 0;
88
+ if ( is_dir( $template_path ) ) {
89
+ foreach ( glob( $template_path . '*.txt' ) as $filename ) {
90
+ $content = file_get_contents( $filename );
91
+ $title = $this->clean_title( $filename );
92
+ $templates[ $i ]['title'] = $title;
93
+ $templates[ $i ]['content'] = $this->clean_content( $content );
94
+ $i++;
95
+ }
96
+ }
97
+
98
+ return $templates;
99
+ }
100
+
101
+ public function debug() {
102
+ if ( ! empty( $templates ) && is_array( $templates ) ) {
103
+ foreach( $templates as $key => $template ) {
104
+ pr( htmlentities( $templates[ $key ]['content'] ) );
105
+ }
106
+ }
107
+ die();
108
+ }
109
+
110
  public function localize_script() {
111
+ $template_path = apply_filters( 'wpc_shortcodes_template_path', null );
112
+
113
+ if ( empty( $template_path ) ) {
114
+ return;
115
+ }
116
+
117
+ $templates = $this->find_templates( $template_path );
118
 
119
  ?>
120
+ <?php if ( ! empty( $templates ) ) : ?>
121
+ <script type="text/javascript">
122
+ var wpc_shortcodes_template_buttons = <?php echo json_encode( $templates ); ?>;
123
+ </script>
124
+ <?php endif; ?>
125
  <?php
126
  }
127
 
public/class-vars.php CHANGED
@@ -8,7 +8,7 @@ class WPC_Shortcodes_Vars {
8
  *
9
  * @var string
10
  */
11
- const VERSION = '3.33';
12
  const DB_VERSION = '1.0';
13
 
14
  /**
8
  *
9
  * @var string
10
  */
11
+ const VERSION = '3.34';
12
  const DB_VERSION = '1.0';
13
 
14
  /**
readme.txt CHANGED
@@ -8,7 +8,7 @@ Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
- A plugin that adds a useful family of shortcodes to your WordPress theme.
12
 
13
  == Description ==
14
 
@@ -113,6 +113,10 @@ See our help article on [how to manually upload a plugin](http://knowledgebase.a
113
 
114
  == Changelog ==
115
 
 
 
 
 
116
  = Version 3.33 =
117
 
118
  * Updated WPC Settings Framework to 1.0.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
+ A plugin that adds a useful family of shortcodes to your WordPress theme.
12
 
13
  == Description ==
14
 
113
 
114
  == Changelog ==
115
 
116
+ = Version 3.34 =
117
+
118
+ * added ability to add custom template shortcodes
119
+
120
  = Version 3.33 =
121
 
122
  * Updated WPC Settings Framework to 1.0.7
wc-shortcodes.php CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://angiemakes.com/feminine-wordpress-blog-themes-women/
5
  Description: A plugin that adds a useful family of shortcodes to your WordPress theme.
6
  Author: Chris Baldelomar
7
  Author URI: http://angiemakes.com/
8
- Version: 3.33
9
  License: GPLv2 or later
10
  */
11
 
5
  Description: A plugin that adds a useful family of shortcodes to your WordPress theme.
6
  Author: Chris Baldelomar
7
  Author URI: http://angiemakes.com/
8
+ Version: 3.34
9
  License: GPLv2 or later
10
  */
11