';
90 |
91 | $tabs = array();
92 |
93 | for ( $i = 1; $i < 6; $i++ ) {
94 |
95 | $prefix = 'tab' . $i;
96 |
97 | if ( ! empty( $atts[ $prefix . '_title' ] ) ) {
98 |
99 | $tab = array(
100 | 'tag' => ( ! empty( $atts['tag'] ) ) ? $atts['tag'] : 'h2',
101 | 'title' => $atts[ $prefix . '_title' ],
102 | 'url' => ( ! empty( $atts[ $prefix . '_url' ] ) ) ? $atts[ $prefix . '_url' ] : '',
103 | 'posts' => ( ! empty( $atts[ $prefix . '_posts' ] ) ) ? $atts[ $prefix . '_posts' ] : '',
104 | 'bgcolor' => ( ! empty( $atts[ $prefix . '_bgcolor' ] ) ) ? $atts[ $prefix . '_bgcolor' ] : '',
105 | 'bgimage' => ( ! empty( $atts[ $prefix . '_img_src' ] ) ) ? $atts[ $prefix . '_img_src' ] : '',
106 | );
107 |
108 | $tabs[ $prefix ] = $tab;
109 |
110 | } // End if
111 | } // End for
112 |
113 | $display = ( ! empty( $atts['display'] ) ) ? $atts['display'] : 'basic';
114 |
115 | switch ( $display ) {
116 |
117 | case 'columns':
118 | $html .= $this->get_display_columns( $tabs, $atts, $content );
119 | break;
120 |
121 | default:
122 | break;
123 |
124 | } // End switch
125 |
126 | return $html . '
';
127 |
128 | } // End get_rendered_shortcode
129 |
130 |
131 | protected function get_display_columns( $tabs, $settings, $content ) {
132 |
133 | \ob_start();
134 |
135 | include __DIR__ . '/column-tabs.php';
136 |
137 | $html = \ob_get_clean();
138 |
139 | return $html;
140 |
141 | } // End get_display_columns
142 |
143 |
144 | /*
145 | * @desc Get HTML for shortcode form
146 | * @since 3.0.0
147 | *
148 | * @param array $atts Shortcode attributes
149 | * @param string $content Shortcode content
150 | *
151 | * @return string HTML shortcode form output
152 | */
153 | public function get_shortcode_form( $id, $settings, $content, $cpb_form ) {
154 |
155 | $cpb_form = cpb_get_form_class();
156 |
157 | $posts = cpb_get_public_posts( array(), true, true );
158 |
159 | $html = '';
160 |
161 | $tags = $cpb_form->get_header_tags();
162 |
163 | unset( $tags['strong'] );
164 |
165 | $html .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'tag' ), $settings['tag'], $tags, 'Tag Type' );
166 |
167 | for ( $i = 1; $i < 6; $i++ ) {
168 |
169 | $html .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'tab' . $i . '_title' ), $settings[ 'tab' . $i . '_title' ], 'Tab ' . $i . ' Title' );
170 |
171 | $html .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'tab' . $i . '_url' ), $settings[ 'tab' . $i . '_url' ], 'Tab ' . $i . ' Link' );
172 |
173 | $html .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'tab' . $i . '_posts' ), $settings[ 'tab' . $i . '_posts' ], $posts, 'Tab ' . $i . ' Content' );
174 |
175 | $html .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'tab' . $i . '_bgcolor' ), $settings[ 'tab' . $i . '_bgcolor' ], $cpb_form->get_wsu_colors(), 'Tab ' . $i . ' Background Color' );
176 |
177 | $html .= $cpb_form->insert_media( cpb_get_input_name( $id, true ), $settings, '', 'tab' . $i . '_' );
178 |
179 | } // End for
180 |
181 | $displays = array(
182 | 'basic' => 'Basic',
183 | 'columns' => 'Columns',
184 | );
185 |
186 | $adv = '';
187 |
188 | $adv .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'display' ), $settings['display'], $displays, 'Display' );
189 |
190 | $adv .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'min_height' ), $settings['min_height'], 'Minimum Height' );
191 |
192 | $adv .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'textcolor' ), $settings['textcolor'], $cpb_form->get_wsu_colors(), 'Text Color' );
193 |
194 | $adv .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'anchor' ), $settings['anchor'], 'Anchor Name' );
195 |
196 | $adv .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'csshook' ), $settings['csshook'], 'CSS Hook' );
197 |
198 | return array(
199 | 'Basic' => $html,
200 | 'Advanced' => $adv,
201 | );
202 |
203 | } // End get_shortcode_form
204 |
205 | } // End Tabs
206 |
207 | $cpb_shortcode_cpbtabs = new Tabs_Shortcode();
208 |
--------------------------------------------------------------------------------
/lib/shortcodes/video/class-video-shortcode.php:
--------------------------------------------------------------------------------
1 | '',
19 | 'vid_type' => '',
20 | 'vid_summary' => ''
21 | );
22 |
23 |
24 | public function __construct() {
25 |
26 | \add_action( 'init', array( $this, 'register_shortcode' ) );
27 |
28 | } // End __construct
29 |
30 |
31 | /*
32 | * @desc Register video shortcode
33 | * @since 3.0.0
34 | */
35 | public function register_shortcode() {
36 |
37 | \add_shortcode( 'video', array( $this, 'get_rendered_shortcode' ) );
38 |
39 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, array(), 'video' );
40 |
41 | cpb_register_shortcode(
42 | 'video',
43 | $args = array(
44 | 'form_callback' => array( $this, 'get_shortcode_form' ),
45 | 'label' => 'Video', // Label of the item
46 | 'render_callback' => array( $this, 'get_rendered_shortcode' ), // Callback to render shortcode
47 | 'editor_render_callback' => array( $this, 'get_editor_content' ), // Callback to render shortcode
48 | 'default_atts' => $default_atts,
49 | 'in_column' => true, // Allow in column
50 | )
51 | );
52 |
53 | } // End register_shortcode
54 |
55 |
56 | /*
57 | * @desc Render the shortcode
58 | * @since 3.0.0
59 | *
60 | * @param array $atts Shortcode attributes
61 | * @param string $content Shortcode content
62 | *
63 | * @return string HTML shortcode output
64 | */
65 | public function get_rendered_shortcode( $atts, $content ) {
66 |
67 | $html = '';
68 |
69 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, $atts, 'video' );
70 |
71 | // Check default settings
72 | $atts = \shortcode_atts( $default_atts, $atts, 'video' );
73 |
74 | if ( ! empty( $atts['vid_id'] ) ) {
75 |
76 | $html .= '';
77 |
78 | switch ( $atts['vid_type'] ) {
79 |
80 | case 'vimeo':
81 | $video_id = $atts['vid_id'];
82 | $video_summary = $this->get_video_id_from_url( $atts['vid_summary'] );
83 | ob_start();
84 | include __DIR__ . '/vimeo-video.php';
85 | $html .= ob_get_clean();
86 | break;
87 | default:
88 | $video_id = $this->get_video_id_from_url( $atts['vid_id'] );
89 | $video_summary = $this->get_video_id_from_url( $atts['vid_summary'] );
90 | ob_start();
91 | include __DIR__ . '/youtube-video.php';
92 | $html .= ob_get_clean();
93 | break;
94 | } // end switch
95 |
96 | $html .= '
';
97 |
98 | } // End if
99 |
100 | return $html;
101 |
102 | } // End get_rendered_shortcode
103 |
104 |
105 | /*
106 | * @desc Override dhe editor content view
107 | * @since 3.0.0
108 | *
109 | * @param array $settings Shortode atts
110 | * @param string $content Shortcode content
111 | *
112 | * @return string HTML for use in Editor
113 | */
114 | public function get_editor_content( $settings, $content ) {
115 |
116 | $html = '';
117 |
118 | if ( ! empty( $settings['vid_id'] ) ) {
119 |
120 | if ( 'youtube' === $settings['vid_type'] ) {
121 |
122 | $video_id = $this->get_video_id_from_url( $settings['vid_id'] );
123 |
124 | $src = 'http://img.youtube.com/vi/' . $video_id . '/default.jpg';
125 |
126 | } else {
127 |
128 | $src = '';
129 |
130 | } // end if
131 |
132 | $vid_style = 'background-image:url( ' . $src . ' );background-position: center center;background-size:cover;';
133 |
134 | } else {
135 |
136 | $vid_style = '';
137 |
138 | } // end if
139 |
140 | $html .= '';
192 |
193 | if($settings['vid_type'] == 'youtube'){
194 | $form_custom .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'vid_id' ), $settings['vid_id'], 'YouTube Video ID' );
195 | }else{
196 | $form_custom .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'vid_id' ), $settings['vid_id'], 'Vimeo Video ID' );
197 | }
198 |
199 | $form_custom .= $cpb_form->textarea_field( cpb_get_input_name( $id, true, 'vid_summary' ), $settings['vid_summary'], 'Video Description', 'cpb-full-width' );
200 |
201 |
202 | $form_custom .= '
';
203 |
204 | $youtube_form = array(
205 | 'name' => cpb_get_input_name( $id, true, 'vid_type' ),
206 | 'value' => 'youtube',
207 | 'selected' => $settings['vid_type'],
208 | 'title' => 'YouTube Video',
209 | 'desc' => 'Display YouTube video by ID',
210 | 'form' => $form_custom,
211 | );
212 |
213 | $vimeo_form = array(
214 | 'name' => cpb_get_input_name( $id, true, 'vid_type' ),
215 | 'value' => 'vimeo',
216 | 'selected' => $settings['vid_type'],
217 | 'title' => 'Vimeo Video',
218 | 'desc' => 'Display Vimeo video by ID',
219 | 'form' => $form_custom,
220 | );
221 |
222 | $html = $cpb_form->multi_form( array( $youtube_form, $vimeo_form ) );
223 |
224 | return $html;
225 |
226 | } // End get_shortcode_form
227 |
228 | } // End Video
229 |
230 | $cpb_shortcode_video = new Video_Shortcode();
231 |
--------------------------------------------------------------------------------
/lib/shortcodes/az-index/class-az-index-shortcode.php:
--------------------------------------------------------------------------------
1 | '',
19 | );
20 |
21 |
22 | public function __construct() {
23 |
24 | $local_query_defaults = cpb_get_local_query_defaults();
25 |
26 | $remote_query_defaults = cpb_get_remote_query_defaults();
27 |
28 | $this->default_settings = array_merge(
29 | $this->default_settings,
30 | $local_query_defaults,
31 | $remote_query_defaults
32 | );
33 |
34 | \add_action( 'init', array( $this, 'register_shortcode' ) );
35 |
36 | } // End __construct
37 |
38 |
39 | /*
40 | * @desc Register az_index shortcode
41 | * @since 3.0.1
42 | */
43 | public function register_shortcode() {
44 |
45 | \add_shortcode( 'az_index', array( $this, 'get_rendered_shortcode' ) );
46 |
47 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, array(), 'az_index' );
48 |
49 | cpb_register_shortcode(
50 | 'az_index',
51 | $args = array(
52 | 'form_callback' => array( $this, 'get_shortcode_form' ),
53 | 'label' => 'AZ Index', // Label of the item
54 | 'render_callback' => array( $this, 'get_rendered_shortcode' ), // Callback to render shortcode
55 | 'default_atts' => $default_atts,
56 | 'in_column' => true, // Allow in column
57 | )
58 | );
59 |
60 | } // End register_shortcode
61 |
62 |
63 | /*
64 | * @desc Render the shortcode
65 | * @since 3.0.1
66 | *
67 | * @param array $atts Shortcode attributes
68 | * @param string $content Shortcode content
69 | *
70 | * @return string HTML shortcode output
71 | */
72 | public function get_rendered_shortcode( $atts, $content ) {
73 |
74 | $html = '';
75 |
76 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, $atts, 'az_index' );
77 |
78 | // Check default settings
79 | $atts = \shortcode_atts( $default_atts, $atts, 'az_index' );
80 |
81 | $atts['count'] = '-1';
82 |
83 | $atts['order_by'] = 'title';
84 |
85 | $atts['order'] = 'ASC';
86 |
87 | $class = ( ! empty( $atts['csshook'] ) ) ? $atts['csshook'] : '';
88 |
89 | $html .= '';
90 |
91 | $items = $this->get_items( $atts );
92 |
93 | $alpha_items = $this->get_alpha_items( $items, $atts );
94 |
95 | ob_start();
96 |
97 | include __DIR__ . '/az-index-nav.php';
98 |
99 | $html .= ob_get_clean();
100 |
101 | $html .= $this->get_az_index_content( $alpha_items, $atts );
102 |
103 | return $html;
104 |
105 | } // End get_rendered_shortcode
106 |
107 |
108 | /*
109 | * @desc Get HTML for shortcode form
110 | * @since 3.0.1
111 | *
112 | * @param array $atts Shortcode attributes
113 | * @param string $content Shortcode content
114 | *
115 | * @return string HTML shortcode form output
116 | */
117 | public function get_shortcode_form( $id, $settings, $content, $cpb_form ) {
118 |
119 | $cpb_form = cpb_get_form_class();
120 |
121 | $feed_form = array(
122 | 'name' => cpb_get_input_name( $id, true, 'source_type' ),
123 | 'value' => 'feed',
124 | 'selected' => $settings['source_type'],
125 | 'title' => 'Feed (This Site)',
126 | 'desc' => 'Load content by category or tag',
127 | 'form' => $cpb_form->get_form_local_query( cpb_get_input_name( $id, true ), $settings ),
128 | );
129 |
130 | $remote_feed_form = array(
131 | 'name' => cpb_get_input_name( $id, true, 'source_type' ),
132 | 'value' => 'remote_feed',
133 | 'selected' => $settings['source_type'],
134 | 'title' => 'Feed (Another Site)',
135 | 'desc' => 'Load external content by category or tag',
136 | 'form' => $cpb_form->get_form_remote_feed( cpb_get_input_name( $id, true ), $settings ),
137 | );
138 |
139 | $html = $cpb_form->multi_form( array( $feed_form, $remote_feed_form ) );
140 |
141 | return array( 'Source' => $html );
142 |
143 | } // End get_shortcode_form
144 |
145 |
146 | protected function get_items( $settings ) {
147 |
148 | $query = cpb_get_query_class();
149 |
150 | switch ( $settings['source_type'] ) {
151 |
152 | case 'feed':
153 | $items = $query->get_local_items( $settings, '' );
154 | break;
155 | case 'remote_feed':
156 | $items = $query->get_remote_items_feed( $settings, '' );
157 | break;
158 |
159 | default:
160 | $items = array();
161 | break;
162 |
163 | } // end switch
164 |
165 | return $items;
166 |
167 | } // End get_items
168 |
169 |
170 | protected function get_alpha_items( $items, $settings ) {
171 |
172 | $alpha = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' );
173 |
174 | $alpha_array = array();
175 |
176 | foreach ( $alpha as $index => $al ) {
177 |
178 | $alpha_array[ $al ] = array();
179 |
180 | } // End foreach
181 |
182 | $alpha_num = array(
183 | 1 => 'o',
184 | 2 => 't',
185 | 3 => 't',
186 | 4 => 'f',
187 | 5 => 'f',
188 | 6 => 's',
189 | 7 => 's',
190 | 8 => 'e',
191 | 9 => 'n',
192 | );
193 |
194 | foreach ( $items as $index => $item ) {
195 |
196 | $let = strtolower( $item['title'][0] );
197 |
198 | if ( array_key_exists( $let, $alpha_num ) ) {
199 |
200 | $let = $alpha_num[ $let ];
201 |
202 | } // End if
203 |
204 | $alpha_array[ $let ][] = $item;
205 |
206 | } // End foreach
207 |
208 | return $alpha_array;
209 |
210 | } // End get_alpha_items
211 |
212 |
213 | protected function get_az_index_content( $alpha_items, $settings ) {
214 |
215 | $html = '
';
216 |
217 | $has_active = true;
218 |
219 | foreach ( $alpha_items as $key => $alpha_set ) {
220 |
221 | $active = '';
222 |
223 | if ( ! empty( $alpha_set ) && $has_active ) {
224 |
225 | $active = ' active';
226 |
227 | $has_active = false;
228 |
229 | } // End if
230 |
231 | $html .= '
';
232 |
233 | if ( ! empty( $alpha_set ) ) {
234 |
235 | $cols = array_chunk( $alpha_set, ceil( count( $alpha_set ) / 3 ) );
236 |
237 | foreach ( $cols as $column => $col_items ) {
238 |
239 | ob_start();
240 |
241 | include __DIR__ . '/az-index.php';
242 |
243 | $html .= ob_get_clean();
244 |
245 | } // End foreach
246 | } // End if
247 |
248 | $html .= '
';
249 |
250 | } // End foreach
251 |
252 | $html .= '
';
253 |
254 | return $html;
255 |
256 | } // End get_az_index_content
257 |
258 | } // End AZ Index
259 |
260 | $cpb_shortcode_az_index = new AZ_Index_Shortcode();
261 |
--------------------------------------------------------------------------------
/lib/shortcodes/content-feed/class-content-feed-shortcode.php:
--------------------------------------------------------------------------------
1 | '',
19 | 'tag' => '',
20 | 'display' => '',
21 | 'unset_excerpt' => '0',
22 | 'unset_title' => '0',
23 | 'unset_link' => '0',
24 | 'as_lightbox' => '0',
25 | 'csshook' => '',
26 | );
27 |
28 |
29 | public function __construct() {
30 |
31 | $local_query_defaults = cpb_get_local_query_defaults();
32 |
33 | $this->default_settings = array_merge( $this->default_settings, $local_query_defaults );
34 |
35 | \add_action( 'init', array( $this, 'register_shortcode' ) );
36 |
37 | } // End __construct
38 |
39 |
40 | /*
41 | * @desc Register action shortcode
42 | * @since 3.0.0
43 | */
44 | public function register_shortcode() {
45 |
46 | \add_shortcode( 'content_feed', array( $this, 'get_rendered_shortcode' ) );
47 |
48 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, array(), 'content_feed' );
49 |
50 | cpb_register_shortcode(
51 | 'content_feed',
52 | $args = array(
53 | 'form_callback' => array( $this, 'get_shortcode_form' ),
54 | 'label' => 'Content Feed', // Label of the item
55 | 'render_callback' => array( $this, 'get_rendered_shortcode' ), // Callback to render shortcode
56 | 'default_atts' => $default_atts,
57 | 'in_column' => true, // Allow in column
58 | )
59 | );
60 |
61 | } // End register_shortcode
62 |
63 |
64 | /*
65 | * @desc Render the shortcode
66 | * @since 3.0.0
67 | *
68 | * @param array $atts Shortcode attributes
69 | * @param string $content Shortcode content
70 | *
71 | * @return string HTML shortcode output
72 | */
73 | public function get_rendered_shortcode( $atts, $content ) {
74 |
75 | $html = '';
76 |
77 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, $atts, 'content_feed' );
78 |
79 | // Check default settings
80 | $atts = \shortcode_atts( $default_atts, $atts, 'content_feed' );
81 |
82 | $post_items = array();
83 |
84 | if ( ! empty( $atts['feed_type'] ) ) {
85 |
86 | switch ( $atts['feed_type'] ) {
87 |
88 | case 'feed':
89 | $post_items = $this->get_post_items_feed( $atts );
90 | break;
91 |
92 | } // end switch
93 | } // end if
94 |
95 | switch ( $atts['display'] ) {
96 |
97 | case 'accordion':
98 | $html .= $this->get_accordion_display( $post_items, $atts );
99 | break;
100 | case 'list':
101 | $html .= $this->get_list_display( $post_items, $atts );
102 |
103 | } // End switch
104 |
105 | if ( $html ) {
106 |
107 | $html = '
' . wp_kses_post( $html ) . '
';
108 |
109 | } // end if
110 |
111 | return $html;
112 |
113 | } // End get_rendered_shortcode
114 |
115 |
116 | protected function get_accordion_display( $post_items, $settings ) {
117 |
118 | $html = '';
119 |
120 | $tag = $settings['tag'];
121 |
122 | foreach ( $post_items as $index => $post_item ) {
123 |
124 | $title = $post_item['title'];
125 |
126 | $content = apply_filters( 'cpb_the_content', \do_shortcode( $post_item['content'] ) );
127 |
128 | \ob_start();
129 |
130 | include cpb_get_plugin_path( '/lib/displays/items/accordion/accordion.php' );
131 |
132 | $html .= \ob_get_clean();
133 |
134 | } // End foreach
135 |
136 | return $html;
137 |
138 | } // End get_accordion_display
139 |
140 |
141 | protected function get_list_display( $post_items, $settings ) {
142 |
143 | $html = '
';
144 |
145 | $tag = $settings['tag'];
146 |
147 | foreach ( $post_items as $index => $post_item ) {
148 |
149 | $link_class = ( ! empty( $post_item['link'] ) ) ? 'has-link' : '';
150 |
151 | $title = $post_item['title'];
152 |
153 | $excerpt = $post_item['excerpt'];
154 |
155 | $link = ( ! empty( $post_item['link'] ) ) ? $post_item['link'] : '';
156 |
157 | \ob_start();
158 |
159 | include cpb_get_plugin_path( '/lib/displays/items/list/list.php' );
160 |
161 | $html .= \ob_get_clean();
162 |
163 | } // End foreach
164 |
165 | $html = '
';
166 |
167 | return $html;
168 |
169 | } // End get_list_display
170 |
171 |
172 | protected function get_post_items_feed( $atts ) {
173 |
174 | $query = cpb_get_query_class();
175 |
176 | $post_items = $query->get_local_items( $atts );
177 |
178 | return $post_items;
179 |
180 | } // End get_items_feed
181 |
182 |
183 | /*
184 | * @desc Get HTML for shortcode form
185 | * @since 3.0.0
186 | *
187 | * @param array $atts Shortcode attributes
188 | * @param string $content Shortcode content
189 | *
190 | * @return string HTML shortcode form output
191 | */
192 | public function get_shortcode_form( $id, $settings, $content, $cpb_form ) {
193 |
194 | $cpb_form = cpb_get_form_class();
195 |
196 | $displays = array(
197 | 'list' => 'List',
198 | 'accordion' => 'Accordion',
199 | );
200 |
201 | $feed_form = array(
202 | 'name' => cpb_get_input_name( $id, true, 'feed_type' ),
203 | 'value' => 'feed',
204 | 'selected' => $settings['feed_type'],
205 | 'title' => 'Feed (This Site)',
206 | 'desc' => 'Load content by category or tag',
207 | 'form' => $cpb_form->get_form_local_query( cpb_get_input_name( $id, true ), $settings ),
208 | );
209 |
210 | $html = $cpb_form->multi_form( array( $feed_form ) );
211 |
212 | $tags = $cpb_form->get_header_tags();
213 |
214 | $display = $cpb_form->select_field( cpb_get_input_name( $id, true, 'display' ), $settings['display'], $displays, 'Display As' );
215 |
216 | $display .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'tag' ), $settings['tag'], $tags, 'Tag Type' );
217 |
218 | $display .= '
';
219 |
220 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_title' ), 1, $settings['unset_title'], 'Hide Title' );
221 |
222 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_excerpt' ), 1, $settings['unset_excerpt'], 'Hide Summary' );
223 |
224 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_link' ), 1, $settings['unset_link'], 'Remove Link' );
225 |
226 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'as_lightbox' ), 1, $settings['as_lightbox'], 'Display Lightbox' );
227 |
228 | $adv = $cpb_form->text_field( cpb_get_input_name( $id, true, 'csshook' ), $settings['csshook'], 'CSS Hook' );
229 |
230 | return array(
231 | 'Source' => $html,
232 | 'Display' => $display,
233 | 'Advanced' => $adv,
234 | );
235 |
236 | } // End get_shortcode_form
237 |
238 | } // End Content Feed
239 |
240 | $cpb_shortcode_action = new Content_Feed_Shortcode();
241 |
--------------------------------------------------------------------------------
/lib/shortcodes/list/class-list-shortcode.php:
--------------------------------------------------------------------------------
1 | '',
19 | 'title_tag' => 'h2',
20 | 'source_type' => '',
21 | 'columns' => '4',
22 | 'unset_excerpt' => '0',
23 | 'unset_title' => '0',
24 | 'unset_img' => '0',
25 | 'unset_link' => '0',
26 | 'excerpt_length' => 'medium',
27 | );
28 |
29 |
30 | public function __construct() {
31 |
32 | $local_query_defaults = cpb_get_local_query_defaults();
33 |
34 | $remote_query_defaults = cpb_get_remote_query_defaults();
35 |
36 | $select_query_defaults = cpb_get_select_query_defaults();
37 |
38 | $this->default_settings = array_merge(
39 | $this->default_settings,
40 | $local_query_defaults,
41 | $remote_query_defaults,
42 | $select_query_defaults
43 | );
44 |
45 | \add_action( 'init', array( $this, 'register_shortcode' ) );
46 |
47 | } // End __construct
48 |
49 |
50 | /*
51 | * @desc Register list shortcode
52 | * @since 3.0.0
53 | */
54 | public function register_shortcode() {
55 |
56 | \add_shortcode( 'list', array( $this, 'get_rendered_shortcode' ) );
57 |
58 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, array(), 'list' );
59 |
60 | cpb_register_shortcode(
61 | 'list',
62 | $args = array(
63 | 'form_callback' => array( $this, 'get_shortcode_form' ),
64 | 'label' => 'Post/Page List', // Label of the item
65 | 'render_callback' => array( $this, 'get_rendered_shortcode' ), // Callback to render shortcode
66 | 'default_atts' => $default_atts,
67 | 'in_column' => true, // Allow in column
68 | )
69 | );
70 |
71 | } // End register_shortcode
72 |
73 |
74 | /*
75 | * @desc Render the shortcode
76 | * @since 3.0.0
77 | *
78 | * @param array $atts Shortcode attributes
79 | * @param string $content Shortcode content
80 | *
81 | * @return string HTML shortcode output
82 | */
83 | public function get_rendered_shortcode( $atts, $content ) {
84 |
85 | $html = '';
86 |
87 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, $atts, 'list' );
88 |
89 | // Check default settings
90 | $atts = \shortcode_atts( $default_atts, $atts, 'list' );
91 |
92 | $post_items = array();
93 |
94 | if ( ! empty( $atts['source_type'] ) ) {
95 |
96 | $query = cpb_get_query_class();
97 |
98 | switch ( $atts['source_type'] ) {
99 |
100 | case 'feed':
101 | $post_items = $query->get_local_items( $atts, '' );
102 | break;
103 | case 'remote_feed':
104 | $post_items = $query->get_remote_items_feed( $atts, '' );
105 | break;
106 | default:
107 | $post_items = array();
108 | break;
109 |
110 | } // end switch
111 |
112 | if ( ! empty( $post_items ) ) {
113 |
114 | if ( ! empty( $atts['title'] ) ) {
115 |
116 | $html .= '<' . esc_attr( $atts['title_tag'] ) . '>' . esc_html( $atts['title'] ) . '' . esc_attr( $atts['title_tag'] ) . '>';
117 |
118 | } // End if
119 |
120 | $html .= '
';
121 |
122 | foreach ( $post_items as $index => $post_item ) {
123 |
124 | $post_item = cpb_check_advanced_display( $post_item, $atts );
125 |
126 | $link = ( ! empty( $post_item['link'] ) ) ? $post_item['link'] : '';
127 |
128 | $title = ( ! empty( $post_item['title'] ) ) ? $post_item['title'] : '';
129 |
130 | $excerpt = ( ! empty( $post_item['excerpt'] ) ) ? $post_item['excerpt'] : '';
131 |
132 | \ob_start();
133 |
134 | include __DIR__ . '/list.php';
135 |
136 | $html .= \ob_get_clean();
137 |
138 | } // end foreach
139 |
140 | $html .= '
';
141 |
142 | } // End if
143 | } // End if
144 |
145 | return $html;
146 |
147 | } // End get_rendered_shortcode
148 |
149 |
150 | /*
151 | * @desc Get HTML for shortcode form
152 | * @since 3.0.0
153 | *
154 | * @param array $atts Shortcode attributes
155 | * @param string $content Shortcode content
156 | *
157 | * @return string HTML shortcode form output
158 | */
159 | public function get_shortcode_form( $id, $settings, $content, $cpb_form ) {
160 |
161 | $cpb_form = cpb_get_form_class();
162 |
163 | $select_form = array(
164 | 'name' => cpb_get_input_name( $id, true, 'source_type' ),
165 | 'value' => 'select',
166 | 'selected' => $settings['source_type'],
167 | 'title' => 'Insert',
168 | 'desc' => 'Insert a specific post/page',
169 | 'form' => $cpb_form->get_form_select_post( cpb_get_input_name( $id, true ), $settings ),
170 | );
171 |
172 | $feed_form = array(
173 | 'name' => cpb_get_input_name( $id, true, 'source_type' ),
174 | 'value' => 'feed',
175 | 'selected' => $settings['source_type'],
176 | 'title' => 'Feed (This Site)',
177 | 'desc' => 'Load content by category or tag',
178 | 'form' => $cpb_form->get_form_local_query( cpb_get_input_name( $id, true ), $settings ),
179 | );
180 |
181 | $remote_feed_form = array(
182 | 'name' => cpb_get_input_name( $id, true, 'source_type' ),
183 | 'value' => 'remote_feed',
184 | 'selected' => $settings['source_type'],
185 | 'title' => 'Feed (Another Site)',
186 | 'desc' => 'Load external content by category or tag',
187 | 'form' => $cpb_form->get_form_remote_feed( cpb_get_input_name( $id, true ), $settings ),
188 | );
189 |
190 | $display = $cpb_form->select_field(
191 | cpb_get_input_name( $id, true, 'columns' ),
192 | $settings['columns'],
193 | array(
194 | 1 => 1,
195 | 2 => 2,
196 | 3 => 3,
197 | 4 => 4,
198 | 5 => 5,
199 | ),
200 | 'Columns'
201 | );
202 |
203 | $excerpt_length = array(
204 | 'short' => 'Short',
205 | 'medium' => 'Medium',
206 | 'long' => 'Long',
207 | 'full' => 'Full',
208 | );
209 |
210 | $display = $cpb_form->text_field( cpb_get_input_name( $id, true, 'title' ), $settings['title'], 'Title' );
211 |
212 | $display .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'excerpt_length' ), $settings['excerpt_length'], $excerpt_length, 'Summary Length' );
213 |
214 | $display .= '
';
215 |
216 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_img' ), 1, $settings['unset_img'], 'Hide Image' );
217 |
218 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_title' ), 1, $settings['unset_title'], 'Hide Title' );
219 |
220 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_excerpt' ), 1, $settings['unset_excerpt'], 'Hide Summary' );
221 |
222 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_link' ), 1, $settings['unset_link'], 'Remove Link' );
223 |
224 | $html = $cpb_form->multi_form( array( $select_form, $feed_form, $remote_feed_form ) );
225 |
226 | return array(
227 | 'Source' => $html,
228 | 'Display' => $display,
229 | );
230 |
231 | } // End get_shortcode_form
232 |
233 | } // End List
234 |
235 | $cpb_shortcode_list = new List_Shortcode();
236 |
--------------------------------------------------------------------------------
/lib/shortcodes/post-gallery/class-post-gallery-shortcode.php:
--------------------------------------------------------------------------------
1 | '',
19 | 'columns' => '4',
20 | 'unset_excerpt' => '0',
21 | 'unset_title' => '0',
22 | 'unset_img' => '0',
23 | 'unset_link' => '0',
24 | 'excerpt_length' => 'medium',
25 | 'tag' => 'h3',
26 | 'promo_type' => 'basic',
27 | );
28 |
29 |
30 | public function __construct() {
31 |
32 | $local_query_defaults = cpb_get_local_query_defaults();
33 |
34 | $remote_query_defaults = cpb_get_rest_query_defaults();
35 |
36 | $select_query_defautls = cpb_get_select_query_defaults();
37 |
38 | $this->default_settings = array_merge(
39 | $this->default_settings,
40 | $local_query_defaults,
41 | $remote_query_defaults,
42 | $select_query_defautls
43 | );
44 |
45 | \add_action( 'init', array( $this, 'register_shortcode' ) );
46 |
47 | } // End __construct
48 |
49 |
50 | /*
51 | * @desc Register postgallery shortcode
52 | * @since 3.0.0
53 | */
54 | public function register_shortcode() {
55 |
56 | \add_shortcode( 'postgallery', array( $this, 'get_rendered_shortcode' ) );
57 |
58 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, array(), 'postgallery' );
59 |
60 | cpb_register_shortcode(
61 | 'postgallery',
62 | $args = array(
63 | 'form_callback' => array( $this, 'get_shortcode_form' ),
64 | 'label' => 'Post Gallery', // Label of the item
65 | 'render_callback' => array( $this, 'get_rendered_shortcode' ), // Callback to render shortcode
66 | 'default_atts' => $default_atts,
67 | 'in_column' => true, // Allow in column
68 | )
69 | );
70 |
71 | } // End register_shortcode
72 |
73 |
74 | /*
75 | * @desc Render the shortcode
76 | * @since 3.0.0
77 | *
78 | * @param array $atts Shortcode attributes
79 | * @param string $content Shortcode content
80 | *
81 | * @return string HTML shortcode output
82 | */
83 | public function get_rendered_shortcode( $atts, $content ) {
84 |
85 | $html = '';
86 |
87 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, $atts, 'postgallery' );
88 |
89 | // Check default settings
90 | $atts = \shortcode_atts( $default_atts, $atts, 'postgallery' );
91 |
92 | $post_items = array();
93 |
94 | if ( ! empty( $atts['source_type'] ) ) {
95 |
96 | $query = cpb_get_query_class();
97 |
98 | switch ( $atts['source_type'] ) {
99 |
100 | case 'feed':
101 | $post_items = $query->get_local_items( $atts, '' );
102 | break;
103 | case 'remote_feed':
104 | $cpb_posts = cpb_get_rest_items( $atts );
105 | $post_items = cpb_convert_legacy_post_items( $cpb_posts );
106 | break;
107 | default:
108 | $post_items = array();
109 | break;
110 |
111 | } // end switch
112 |
113 | if ( ! empty( $post_items ) ) {
114 |
115 | $columns = $atts['columns'];
116 |
117 | $type = $atts['promo_type'];
118 |
119 | $tag = $atts['tag'];
120 |
121 | $html .= '
';
122 |
123 | $classes_array = array(
124 | 'cpb-gallery',
125 | 'cpb-gallery-columns-' . $columns,
126 | 'cpb-gallery-' . $type,
127 | );
128 |
129 | $classes = implode( ' ', $classes_array );
130 |
131 | foreach ( $post_items as $index => $post_item ) {
132 |
133 | $post_item = cpb_check_advanced_display( $post_item, $atts );
134 |
135 | $link = ( ! empty( $post_item['link'] ) ) ? $post_item['link'] : '';
136 |
137 | $title = ( ! empty( $post_item['title'] ) ) ? $post_item['title'] : '';
138 |
139 | $excerpt = ( ! empty( $post_item['excerpt'] ) ) ? $post_item['excerpt'] : '';
140 |
141 | $img_src = ( ! empty( $post_item['img'] ) ) ? $post_item['img'] : '';
142 |
143 | if ( ! empty( $img_src ) ) {
144 |
145 | $classes .= ' has-image';
146 |
147 | } // End if
148 |
149 | \ob_start();
150 |
151 | include __DIR__ . '/post-gallery.php';
152 |
153 | $html .= \ob_get_clean();
154 |
155 | } // end foreach
156 |
157 | $html .= '
';
158 |
159 | } // End if
160 | } // End if
161 |
162 | return $html;
163 |
164 | } // End get_rendered_shortcode
165 |
166 |
167 | /*
168 | * @desc Get HTML for shortcode form
169 | * @since 3.0.0
170 | *
171 | * @param array $atts Shortcode attributes
172 | * @param string $content Shortcode content
173 | *
174 | * @return string HTML shortcode form output
175 | */
176 | public function get_shortcode_form( $id, $settings, $content, $cpb_form ) {
177 |
178 | $cpb_form = cpb_get_form_class();
179 |
180 | $select_form = array(
181 | 'name' => cpb_get_input_name( $id, true, 'source_type' ),
182 | 'value' => 'select',
183 | 'selected' => $settings['source_type'],
184 | 'title' => 'Insert',
185 | 'desc' => 'Insert a specific post/page',
186 | 'form' => $cpb_form->get_form_select_post( cpb_get_input_name( $id, true ), $settings ),
187 | );
188 |
189 | $feed_form = array(
190 | 'name' => cpb_get_input_name( $id, true, 'source_type' ),
191 | 'value' => 'feed',
192 | 'selected' => $settings['source_type'],
193 | 'title' => 'Feed (This Site)',
194 | 'desc' => 'Load content by category or tag',
195 | 'form' => $cpb_form->get_form_local_query( cpb_get_input_name( $id, true ), $settings ),
196 | );
197 |
198 | $remote_feed_form = array(
199 | 'name' => cpb_get_input_name( $id, true, 'source_type' ),
200 | 'value' => 'remote_feed',
201 | 'selected' => $settings['source_type'],
202 | 'title' => 'Feed (Another Site)',
203 | 'desc' => 'Load external content by category or tag',
204 | 'form' => $cpb_form->get_form_external_feed( cpb_get_input_name( $id, true ), $settings ),
205 | );
206 |
207 | $display = $cpb_form->select_field(
208 | cpb_get_input_name(
209 | $id,
210 | true,
211 | 'columns'
212 | ),
213 | $settings['columns'],
214 | array(
215 | 1 => 1,
216 | 2 => 2,
217 | 3 => 3,
218 | 4 => 4,
219 | 5 => 5,
220 | ),
221 | 'Columns'
222 | );
223 |
224 | $excerpt_length = array(
225 | 'short' => 'Short',
226 | 'medium' => 'Medium',
227 | 'long' => 'Long',
228 | 'full' => 'Full',
229 | );
230 |
231 | $display .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'excerpt_length' ), $settings['excerpt_length'], $excerpt_length, 'Summary Length' );
232 |
233 | $tags = $cpb_form->get_header_tags();
234 | unset( $tags['strong'] );
235 | $display .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'tag' ), $settings['tag'], $tags, 'Tag Type' );
236 |
237 | $display .= '
';
238 |
239 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_img' ), 1, $settings['unset_img'], 'Hide Image' );
240 |
241 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_title' ), 1, $settings['unset_title'], 'Hide Title' );
242 |
243 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_excerpt' ), 1, $settings['unset_excerpt'], 'Hide Summary' );
244 |
245 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_link' ), 1, $settings['unset_link'], 'Remove Link' );
246 |
247 | $html = $cpb_form->multi_form( array( $select_form, $feed_form, $remote_feed_form ) );
248 |
249 | return array(
250 | 'Source' => $html,
251 | 'Display' => $display,
252 | );
253 |
254 | } // End get_shortcode_form
255 |
256 |
257 | } // End Post Gallery
258 |
259 | $cpb_shortcode_postgallery = new Post_Gallery_Shortcode();
260 |
--------------------------------------------------------------------------------
/lib/shortcodes/social/class-social-shortcode.php:
--------------------------------------------------------------------------------
1 | '',
19 | 'twitter_order' => '',
20 | 'facebook' => '',
21 | 'facebook_order' => '',
22 | 'instagram' => '',
23 | 'instagram_order' => '',
24 | 'instagram_target' => '',
25 | 'height' => '',
26 | 'csshook' => '',
27 | );
28 |
29 |
30 | public function __construct() {
31 |
32 | \add_action( 'init', array( $this, 'register_shortcode' ) );
33 |
34 | } // End __construct
35 |
36 |
37 | /*
38 | * @desc Register social shortcode
39 | * @since 3.0.0
40 | */
41 | public function register_shortcode() {
42 |
43 | \add_shortcode( 'social', array( $this, 'get_rendered_shortcode' ) );
44 |
45 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, array(), 'social' );
46 |
47 | cpb_register_shortcode(
48 | 'social',
49 | $args = array(
50 | 'form_callback' => array( $this, 'get_shortcode_form' ),
51 | 'label' => 'Social', // Label of the item
52 | 'render_callback' => array( $this, 'get_rendered_shortcode' ), // Callback to render shortcode
53 | 'default_atts' => $default_atts,
54 | 'in_column' => true, // Allow in column
55 | )
56 | );
57 |
58 | } // End register_shortcode
59 |
60 |
61 | /*
62 | * @desc Render the shortcode
63 | * @since 3.0.0
64 | *
65 | * @param array $atts Shortcode attributes
66 | * @param string $content Shortcode content
67 | *
68 | * @return string HTML shortcode output
69 | */
70 | public function get_rendered_shortcode( $atts, $content ) {
71 |
72 | $html = '';
73 |
74 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, $atts, 'social' );
75 |
76 | // Check default settings
77 | $atts = \shortcode_atts( $default_atts, $atts, 'social' );
78 |
79 | if ( empty( $atts['height'] ) ) {
80 |
81 | $atts['height'] = 800;
82 |
83 | } // end if
84 |
85 | $feeds = array();
86 |
87 | if ( ! empty( $atts['twitter'] ) ) {
88 |
89 | $order = ( ! empty( $atts['twitter_order'] ) ) ? $atts['twitter_order'] : 2;
90 |
91 | $feeds[ $order ] = array(
92 | 'type' => 'twitter',
93 | 'src' => $atts['twitter'],
94 | 'height' => $atts['height'],
95 | );
96 |
97 | } // End if
98 |
99 | if ( ! empty( $atts['facebook'] ) ) {
100 |
101 | $order = ( ! empty( $atts['facebook_order'] ) ) ? $atts['facebook_order'] : 3;
102 |
103 | $feeds[ $order ] = array(
104 | 'type' => 'facebook',
105 | 'src' => $atts['facebook'],
106 | 'height' => $atts['height'],
107 | );
108 |
109 | } // End if
110 |
111 | if ( ! empty( $atts['instagram'] ) ) {
112 |
113 | $order = ( ! empty( $atts['instagram_order'] ) ) ? $atts['instagram_order'] : 4;
114 |
115 | $feeds[ $order ] = array(
116 | 'type' => 'instagram',
117 | 'src' => $atts['instagram'],
118 | 'height' => $atts['height'],
119 | 'target' => $atts['instagram_target'],
120 | 'is_link' => true,
121 | );
122 |
123 | } // End if
124 |
125 | $html = '
';
126 |
127 | ksort( $feeds );
128 |
129 | $icon_html = '
';
130 |
131 | $content_html = '
';
132 |
133 | $i = 0;
134 |
135 | foreach ( $feeds as $index => $feed ) {
136 |
137 | $active = ( 0 === $i ) ? ' active' : '';
138 |
139 | $content_html .= '
';
140 |
141 | switch ( $feed['type'] ) {
142 |
143 | case 'facebook':
144 | $icon_html .= $this->get_facebook_html( $feed, $i, true );
145 | $content_html .= $this->get_facebook_html( $feed, $i );
146 | break;
147 | case 'twitter':
148 | $icon_html .= $this->get_twitter_html( $feed, $i, true );
149 | $content_html .= $this->get_twitter_html( $feed, $i );
150 | break;
151 | case 'instagram':
152 | $icon_html .= $this->get_instagram_html( $feed, $i, true );
153 | $content_html .= $this->get_instagram_html( $feed, $i );
154 | break;
155 | } // End
156 |
157 | $content_html .= '
';
158 |
159 | $i++;
160 |
161 | } // end foreach
162 |
163 | $icon_html .= '
';
164 |
165 | $content_html .= '
';
166 |
167 | $html .= $icon_html . $content_html . '
';
168 |
169 | return $html;
170 |
171 | } // End get_rendered_shortcode
172 |
173 |
174 | protected function get_facebook_html( $feed, $i, $is_icon = false ) {
175 |
176 | $html = '';
177 |
178 | $height = $feed['height'];
179 |
180 | if ( $is_icon ) {
181 |
182 | $html .= '
';
183 |
184 | } else {
185 |
186 | $facebook_src = $feed['src'];
187 |
188 | \ob_start();
189 |
190 | include __DIR__ . '/facebook.php';
191 |
192 | $html .= \ob_get_clean();
193 |
194 | } // End if
195 |
196 | return $html;
197 |
198 | } // End get_facebook_html
199 |
200 |
201 | protected function get_twitter_html( $feed, $i, $is_icon = false ) {
202 |
203 | $html = '';
204 |
205 | $height = $feed['height'];
206 |
207 | if ( $is_icon ) {
208 |
209 | $html .= '';
210 |
211 | } else {
212 |
213 | $twitter_src = $feed['src'];
214 |
215 | \ob_start();
216 |
217 | include __DIR__ . '/twitter.php';
218 |
219 | $html .= \ob_get_clean();
220 |
221 | } // End if
222 |
223 | return $html;
224 |
225 | } // End get_facebook_html
226 |
227 | protected function get_instagram_html( $feed, $i, $is_icon = false ) {
228 |
229 | $html = '';
230 |
231 | $height = $feed['height'];
232 |
233 | if ( $is_icon ) {
234 |
235 | $html .= '
text_field( cpb_get_input_name( $id, true, 'twitter' ), $settings['twitter'], 'Twitter URL' );
270 |
271 | $html .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'twitter_order' ), $settings['twitter_order'], 'Twitter Order' );
272 |
273 | $html .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'facebook' ), $settings['facebook'], 'Facebook URL' );
274 |
275 | $html .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'facebook_order' ), $settings['facebook_order'], 'Facebook Order' );
276 |
277 | $html .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'instagram' ), $settings['instagram'], 'Instagram URL' );
278 |
279 | $html .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'instagram_order' ), $settings['instagram_order'], 'Instagram Order' );
280 |
281 | $html .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'instagram_target' ), 1, $settings['instagram_target'], 'Instagram: Open In New Window' );
282 |
283 | $html .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'height' ), $settings['height'], 'height (no px)' );
284 |
285 | $html .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'csshook' ), $settings['csshook'], 'CSS Hook' );
286 |
287 | return $html;
288 |
289 | } // End get_shortcode_form
290 |
291 | } // End Social
292 |
293 | $cpb_shortcode_social = new Social_Shortcode();
294 |
--------------------------------------------------------------------------------
/lib/includes/class-editor.php:
--------------------------------------------------------------------------------
1 | add_actions();
19 |
20 | // Add plugin filters
21 | $this->add_filters();
22 |
23 | } // End __construct
24 |
25 |
26 | /*
27 | * @desc Add WP actions for the plugin
28 | * @since 3.0.0
29 | */
30 | protected function add_actions() {
31 |
32 | // Add editor to edit post page
33 | \add_action( 'edit_form_after_title', array( $this, 'add_editor' ), 10 );
34 |
35 | } // End add_actions
36 |
37 |
38 | /*
39 | * @desc Add WP filters for the plugin
40 | * @since 3.0.0
41 | */
42 | protected function add_filters() {
43 |
44 | } // End add_actions
45 |
46 |
47 | /*
48 | * @desc Add Editor to post type
49 | * @since 3.0.0
50 | */
51 | public function add_editor( $post ) {
52 |
53 | $customizer_key = 'cpb_enable_post_type_' . $post->post_type;
54 |
55 | $default = ( 'page' === $post->post_type ) ? 1 : 0;
56 |
57 | $is_enabled = get_theme_mod( $customizer_key, $default );
58 |
59 | if ( ! empty( $is_enabled ) ) {
60 |
61 | $cpb_shortcodes = cpb_get_shortcodes( false );
62 |
63 | $content_shortcodes = cpb_get_shortcodes_from_content( $post->post_content, array( 'row' ), 'row' );
64 |
65 | $editor_type = $this->get_editor_type( $post->ID );
66 |
67 | $options_editor = $this->get_options_editor( $post );
68 |
69 | if ( 'builder' === $editor_type ) {
70 |
71 | $layout_editor = $this->get_layout_editor( $content_shortcodes );
72 |
73 | $form_editor = $this->get_form_editor( $content_shortcodes );
74 |
75 | $excerpt_editor = $this->get_excerpt_editor( $post );
76 |
77 | remove_post_type_support( $post->post_type, 'editor' );
78 |
79 | remove_post_type_support( $post->post_type, 'excerpt' );
80 |
81 | } else {
82 |
83 | $layout_editor = '';
84 |
85 | $form_editor = '';
86 |
87 | $excerpt_editor = '';
88 |
89 | } // End if
90 |
91 | \ob_start();
92 |
93 | include cpb_get_plugin_path( '/lib/displays/editor/editor.php' );
94 |
95 | $html = \ob_get_clean();
96 |
97 | // @codingStandardsIgnoreStart Already escaped
98 | echo $html;
99 | // @codingStandardsIgnoreEnd
100 |
101 | } // End if
102 |
103 | } // End add_editor
104 |
105 |
106 | /*
107 | * @desc Get HTML for layout editor
108 | * @since 3.0.0
109 | *
110 | * @param array $content_shortcodes Array of shortcodes
111 | *
112 | * @return string HTML of layout editor
113 | */
114 | protected function get_options_editor( $post ) {
115 |
116 | $values = array(
117 | 'default' => 'Default Editor',
118 | 'builder' => 'Layout Editor',
119 | );
120 |
121 | $cpb = \get_post_meta( $post->ID, '_cpb_pagebuilder', true );
122 |
123 | if ( '' === $cpb ) {
124 |
125 | $cpb = 'builder';
126 |
127 | } elseif ( '0' === $cpb ) {
128 |
129 | $cpb = 'default';
130 |
131 | } elseif ( '1' === $cpb ) {
132 |
133 | $cpb = 'builder';
134 |
135 | }; // End if
136 |
137 | \ob_start();
138 |
139 | include cpb_get_plugin_path( '/lib/displays/editor/options-editor.php' );
140 |
141 | $html = \ob_get_clean();
142 |
143 | return $html;
144 |
145 | } // End get_layout_editor
146 |
147 |
148 | /*
149 | * @desc Get HTML for layout editor
150 | * @since 3.0.0
151 | *
152 | * @param array $content_shortcodes Array of shortcodes
153 | *
154 | * @return string HTML of layout editor
155 | */
156 | protected function get_layout_editor( $content_shortcodes ) {
157 |
158 | $child_ids = array();
159 |
160 | $editor_content = cpb_get_editor_html( $content_shortcodes );
161 |
162 | $child_ids = cpb_get_child_shortcode_ids( $content_shortcodes );
163 |
164 | $child_ids = \implode( ',', $child_ids );
165 |
166 | $add_shortcode_form = $this->get_add_shortcode_form();
167 |
168 | $add_row_form = $this->get_add_row_form();
169 |
170 | \ob_start();
171 |
172 | include cpb_get_plugin_path( '/lib/displays/editor/layout-editor.php' );
173 |
174 | $html = \ob_get_clean();
175 |
176 | return $html;
177 |
178 | } // End get_layout_editor
179 |
180 |
181 | /*
182 | * @desc Get HTML for form editor
183 | * @since 3.0.0
184 | *
185 | * @param array $content_shortcodes Array of shortcodes
186 | *
187 | * @return string HTML of form editor
188 | */
189 | protected function get_form_editor( $content_shortcodes ) {
190 |
191 | $content_shortcodes_flat = cpb_flatten_shortcode_array( $content_shortcodes );
192 |
193 | $form_html = '';
194 |
195 | $empty_editors = '';
196 |
197 | if ( is_array( $content_shortcodes_flat ) ) {
198 |
199 | foreach ( $content_shortcodes_flat as $index => $shortcode ) {
200 |
201 | $form_html .= cpb_get_editor_form_html( $shortcode );
202 |
203 | } // End foreach
204 | } // End if
205 |
206 | $text_editors = array( 'textblock' );
207 |
208 | foreach ( $text_editors as $text_editor ) {
209 |
210 | for ( $i = 0; $i < 10; $i++ ) {
211 |
212 | $text_shortcode = cpb_get_shortcode( $text_editor, array(), '', false );
213 |
214 | $text_shortcode['form_classes'] = array( 'cpb-blank-editor' );
215 |
216 | $empty_editors .= cpb_get_editor_form_html( $text_shortcode );
217 |
218 | } // end for
219 | } // end foreach
220 |
221 | \ob_start();
222 |
223 | include cpb_get_plugin_path( '/lib/displays/editor/form-editor.php' );
224 |
225 | $html = \ob_get_clean();
226 |
227 | return $html;
228 |
229 | } // End get_layout_editor
230 |
231 |
232 | /*
233 | * @desc Get HTML for excerpt editor
234 | * @since 3.0.0
235 | *
236 | * @param WP_Post $post Current Post
237 | *
238 | * @return string HTML of editor
239 | */
240 | protected function get_excerpt_editor( $post ) {
241 |
242 | $excerpt_type = \get_post_meta( $post->ID, '_cpb_m_excerpt', true );
243 |
244 | if ( '' === $excerpt_type ) {
245 |
246 | $excerpt_type = 0;
247 |
248 | } else {
249 |
250 | $excerpt_type = intval( $excerpt_type );
251 |
252 | }// End if
253 |
254 | $values = array( 'Default Excerpt', 'Custom Excerpt' );
255 |
256 | \ob_start();
257 |
258 | include cpb_get_plugin_path( '/lib/displays/editor/excerpt-editor.php' );
259 |
260 | $html = \ob_get_clean();
261 |
262 | return $html;
263 |
264 | } // End get_excerpt_editor
265 |
266 |
267 | /*
268 | * @desc Get form HTML for adding rows
269 | * @since 3.0.0
270 | *
271 | * @return string HTML for form
272 | */
273 | protected function get_add_row_form() {
274 |
275 | $layouts = array(
276 | 'single' => 'Single Column',
277 | 'halves' => 'Two Column',
278 | 'side-right' => 'Two Column: Sidebar Right',
279 | 'side-left' => 'Two Column: Sidbar Left',
280 | 'thirds' => 'Three Column',
281 | 'thirds-half-left' => 'Three Column: Left 50%',
282 | 'thirds-half-right' => 'Three Column: Right 50% ',
283 | 'triptych' => 'Three Column: Middle 50%',
284 | 'quarters' => 'Four Column',
285 | );
286 |
287 | \ob_start();
288 |
289 | include cpb_get_plugin_path( '/lib/displays/editor/add-row-editor.php' );
290 |
291 | $html = \ob_get_clean();
292 |
293 | return $html;
294 |
295 | } // end get_add_row_form
296 |
297 |
298 | /*
299 | * @desc Get form HTML for adding rows
300 | * @since 3.0.0
301 | *
302 | * @return string HTML for form
303 | */
304 | protected function get_add_shortcode_form() {
305 |
306 | $shortcodes = cpb_get_shortcodes( false, true );
307 |
308 | \ob_start();
309 |
310 | include cpb_get_plugin_path( '/lib/displays/editor/add-shortcode-editor.php' );
311 |
312 | $shortcode_html = \ob_get_clean();
313 |
314 | $form_content = array( 'Select Item' => $shortcode_html );
315 |
316 | $form_args = array( 'title' => 'Add Items & Widgets' );
317 |
318 | $html = cpb_get_editor_form_wrapper( 'cpb-add-item-form', $form_content, $form_args );
319 |
320 | return $html;
321 |
322 | } // end get_add_row_form
323 |
324 |
325 | /*
326 | * @desc Get editor type from post id
327 | * @since 3.0.4
328 | *
329 | * @param int $post_id Post ID
330 | *
331 | * @return string Name of editor to be used default | builder
332 | */
333 | protected function get_editor_type( $post_id ) {
334 |
335 | $cpb = \get_post_meta( $post_id, '_cpb_pagebuilder', true );
336 |
337 | if ( '' === $cpb ) {
338 |
339 | $cpb = 'builder';
340 |
341 | } elseif ( '0' === $cpb ) {
342 |
343 | $cpb = 'default';
344 |
345 | } elseif ( '1' === $cpb ) {
346 |
347 | $cpb = 'builder';
348 |
349 | }; // End if
350 |
351 | return $cpb;
352 |
353 | } // End get_editor_type
354 |
355 |
356 | } // End Editor
357 |
358 | $cpb_editor = new Editor();
359 |
--------------------------------------------------------------------------------
/lib/shortcodes/column/class-column-shortcode.php:
--------------------------------------------------------------------------------
1 | '',
19 | 'bgcolor' => '',
20 | 'textcolor' => '',
21 | 'csshook' => '',
22 | 'padding_top' => '',
23 | 'padding_bottom' => '',
24 | 'padding_left' => '',
25 | 'padding_right' => '',
26 | );
27 |
28 |
29 | public function __construct() {
30 |
31 | \add_action( 'init', array( $this, 'register_shortcode' ) );
32 |
33 | } // End __construct
34 |
35 |
36 | /*
37 | * @desc Register column shortcode
38 | * @since 3.0.0
39 | */
40 | public function register_shortcode() {
41 |
42 | \add_shortcode( 'column', array( $this, 'get_rendered_shortcode' ) );
43 |
44 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, array(), 'column' );
45 |
46 | cpb_register_shortcode(
47 | 'column',
48 | $args = array(
49 | 'form_callback' => array( $this, 'get_shortcode_form' ),
50 | 'editor_callback' => array( $this, 'get_shortcode_editor' ), // Callback to render form
51 | 'allowed_children' => 'in_column', // Allowed child shortcodes,
52 | 'default_shortcode' => 'textblock', // Default to this if no children
53 | 'default_atts' => $default_atts,
54 | 'in_column' => false, // Allow in column
55 | )
56 | );
57 |
58 | } // End register_shortcode
59 |
60 |
61 | /*
62 | * @desc Render the shortcode
63 | * @since 3.0.0
64 | *
65 | * @param array $atts Shortcode attributes
66 | * @param string $content Shortcode content
67 | *
68 | * @return string HTML shortcode output
69 | */
70 | public function get_rendered_shortcode( $atts, $content ) {
71 |
72 | // Column index global - This is used in the column shortcode to get column number.
73 | global $cpb_column_i;
74 |
75 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, $atts, 'column' );
76 |
77 | // Check default settings
78 | $settings = \shortcode_atts( $default_atts, $atts, 'column' );
79 |
80 | $settings['index'] = $cpb_column_i;
81 |
82 | // Set column classes
83 | $classes = $this->get_column_classes( $settings );
84 |
85 | $cpb_column_i++;
86 |
87 | // Column layout global
88 | global $cpb_column_layout;
89 |
90 | // Get the style array
91 | $style_array = $this->get_column_style( $settings );
92 |
93 | // Implode the array to string
94 | $style = implode( ';', $style_array );
95 |
96 | $prefix = $this->prefix;
97 |
98 | \ob_start();
99 |
100 | include __DIR__ . '/column.min.php';
101 |
102 | $html = \ob_get_clean();
103 |
104 | return $html;
105 |
106 | } // End get_rendered_shortcode
107 |
108 |
109 | /*
110 | * @desc Get HTML for shortcode form
111 | * @since 3.0.0
112 | *
113 | * @param array $atts Shortcode attributes
114 | * @param string $content Shortcode content
115 | *
116 | * @return string HTML shortcode form output
117 | */
118 | public function get_shortcode_form( $id, $atts, $content, $cpb_form ) {
119 |
120 | $cpb_form = cpb_get_form_class();
121 |
122 | $p_values = array(
123 | 'default' => 'Not Set',
124 | );
125 |
126 | $p = 0;
127 |
128 | while ( $p < 5 ) {
129 |
130 | $p_values[ $p . 'rem' ] = $p . 'rem';
131 |
132 | $p = $p + 0.25;
133 |
134 | } // end for
135 |
136 | $basic = $cpb_form->select_field( cpb_get_input_name( $id, true, 'bgcolor' ), $atts['bgcolor'], $cpb_form->get_wsu_colors(), 'Background Color' );
137 |
138 | $basic .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'textcolor' ), $atts['textcolor'], $cpb_form->get_wsu_colors(), 'Text Color' );
139 |
140 | $layout = $cpb_form->select_field( cpb_get_input_name( $id, true, 'padding_top' ), $atts['padding_top'], $p_values, 'Padding Top' );
141 |
142 | $layout .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'padding_bottom' ), $atts['padding_bottom'], $p_values, 'Padding Bottom' );
143 |
144 | $layout .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'padding_left' ), $atts['padding_left'], $p_values, 'Padding Left' );
145 |
146 | $layout .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'padding_right' ), $atts['padding_right'], $p_values, 'Padding Right' );
147 |
148 | $adv = $cpb_form->text_field( cpb_get_input_name( $id, true, 'csshook' ), $atts['csshook'], 'CSS Hook' );
149 |
150 | return array(
151 | 'Basic' => $basic,
152 | 'Layout' => $layout,
153 | 'Advanced' => $adv,
154 | );
155 |
156 | } // End get_shortcode_form
157 |
158 |
159 | /*
160 | * @desc Get HTML for shortcode editor
161 | * @since 3.0.0
162 | *
163 | * @param string $id Shortcode id
164 | * @param array $atts Shortcode attributes
165 | * @param string $content Shortcode content
166 | * @param string $children Shortcode children
167 | *
168 | * @return string HTML shortcode form output
169 | */
170 | public function get_shortcode_editor( $id, $atts, $content, $children ) {
171 |
172 | // Column index global - This is used in the column shortcode to get column number.
173 | global $cpb_column_i;
174 |
175 | // Set index int value
176 | $index_int = $cpb_column_i;
177 |
178 | // Set index text value
179 | $index = cpb_convert_int_to_string( $cpb_column_i );
180 |
181 | // increment column global var
182 | $cpb_column_i++;
183 |
184 | // Get editor content html
185 | $editor_content = cpb_get_editor_html( $children );
186 |
187 | // Get input name
188 | $input_name = cpb_get_input_name( $id );
189 |
190 | // Get child kes as array
191 | $child_keys = cpb_get_child_shortcode_ids( $children );
192 |
193 | // Implode array
194 | $child_keys = \implode( ',', $child_keys );
195 |
196 | // Get the edit button
197 | $edit_button = cpb_get_editor_edit_button();
198 |
199 | // Get the remove button
200 | $remove_button = cpb_get_editor_remove_button();
201 |
202 | // Start the output buffer
203 | \ob_start();
204 |
205 | // Include the html for the column editor
206 | include cpb_get_plugin_path( '/lib/displays/editor/column-editor.php' );
207 |
208 | // Get the html
209 | $html = \ob_get_clean();
210 |
211 | return $html;
212 |
213 | } // End get_shortcode_form
214 |
215 |
216 | /*
217 | * @desc Get stanitized output for $atts
218 | * @since 3.0.0
219 | *
220 | * @param array $atts Shortcode attributes
221 | * @param string $content Shortcode content
222 | *
223 | * @return array Sanitized shortcode $atts
224 | */
225 | public function get_sanitize_shortcode_atts( $atts ) {
226 |
227 | } // End sanitize_shortcode
228 |
229 |
230 | /*
231 | * @desc Get shortcode for use in save
232 | * @since 3.0.0
233 | *
234 | * @param array $atts Shortcode attributes
235 | * @param string $content Shortcode content
236 | *
237 | * @return string Shortcode for saving in content
238 | */
239 | public function get_to_shortcode( $atts, $content ) {
240 |
241 | } // End
242 |
243 |
244 | /*
245 | * @desc Get column classes
246 | * @since 3.0.0
247 | *
248 | * @param array $settings Column attributes
249 | *
250 | * @return string Column classes
251 | */
252 | private function get_column_classes( $settings ) {
253 |
254 | $class = 'cpb-column ';
255 |
256 | $index_list = 'zero,one,two,three,four,five,six,seven,eight,nine,ten';
257 |
258 | $index_list = explode( ',', $index_list );
259 |
260 | $class .= ' ' . $index_list[ $settings['index'] ];
261 |
262 | if ( ! empty( $settings['bgcolor'] ) ) {
263 |
264 | $class .= ' ' . $settings['bgcolor'] . '-back bg-color';
265 |
266 | } // end if
267 |
268 | if ( ! empty( $settings['csshook'] ) ) {
269 |
270 | $class .= ' ' . $settings['csshook'];
271 |
272 | } // end if
273 |
274 | if ( ! empty( $settings['textcolor'] ) ) {
275 |
276 | $class .= ' ' . $settings['textcolor'] . '-text';
277 |
278 | } // end if
279 |
280 | return $class;
281 |
282 | } // End get_item_class
283 |
284 | /*
285 | * @desc Get column style
286 | * @since 3.0.0
287 | *
288 | * @param array $settings Column attributes
289 | *
290 | * @return array Column css
291 | */
292 | protected function get_column_style( $settings ) {
293 |
294 | $style = array();
295 |
296 | $valid = array(
297 | 'padding_top' => 'padding-top',
298 | 'padding_bottom' => 'padding-bottom',
299 | 'padding_left' => 'padding-left',
300 | 'padding_right' => 'padding-right',
301 | 'max_width' => 'max-width',
302 | );
303 |
304 | foreach ( $settings as $key => $value ) {
305 |
306 | if ( array_key_exists( $key, $valid ) && 'default' !== $value && '' !== $value ) {
307 |
308 | $css = $valid[ $key ];
309 |
310 | $style[] = $css . ':' . $value;
311 |
312 | } // end if
313 | } // end foreach
314 |
315 | return $style;
316 |
317 | } // end get_item_style
318 |
319 | } // End Column
320 |
321 | $cpb_shortcode_column = new Column();
322 |
--------------------------------------------------------------------------------
/lib/shortcodes/slide/class-slide-shortcode.php:
--------------------------------------------------------------------------------
1 | '',
19 | 'img_src' => '',
20 | 'img_id' => '',
21 | 'link' => '',
22 | 'item_title' => '',
23 | 'subtitle' => '',
24 | 'excerpt' => '',
25 | 'columns' => '4',
26 | 'tag' => 'h5',
27 | 'img_ratio' => 'spacer1x1',
28 | 'unset_excerpt' => '0',
29 | 'unset_title' => '0',
30 | 'unset_img' => '0',
31 | 'unset_link' => '0',
32 | 'stack_vertical' => '0',
33 | 'as_lightbox' => '0',
34 | 'csshook' => '',
35 | );
36 |
37 |
38 | public function __construct() {
39 |
40 | $local_query_defaults = cpb_get_local_query_defaults();
41 |
42 | $remote_query_defaults = cpb_get_remote_query_defaults();
43 |
44 | $select_query_defaults = cpb_get_select_query_defaults();
45 |
46 | $this->default_settings = array_merge(
47 | $this->default_settings,
48 | $local_query_defaults,
49 | $remote_query_defaults,
50 | $select_query_defaults
51 | );
52 |
53 | \add_action( 'init', array( $this, 'register_shortcode' ) );
54 |
55 | } // End __construct
56 |
57 |
58 | /*
59 | * @desc Register slide shortcode
60 | * @since 3.0.0
61 | */
62 | public function register_shortcode() {
63 |
64 | \add_shortcode( 'slide', array( $this, 'get_rendered_shortcode' ) );
65 |
66 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, array(), 'slide' );
67 |
68 | cpb_register_shortcode(
69 | 'slide',
70 | $args = array(
71 | 'form_callback' => array( $this, 'get_shortcode_form' ),
72 | 'label' => 'Slide', // Label of the item
73 | 'render_callback' => array( $this, 'get_rendered_shortcode' ), // Callback to render shortcode
74 | 'default_atts' => $default_atts,
75 | 'in_column' => true, // Allow in column
76 | )
77 | );
78 |
79 | } // End register_shortcode
80 |
81 |
82 | /*
83 | * @desc Render the shortcode
84 | * @since 3.0.0
85 | *
86 | * @param array $atts Shortcode attributes
87 | * @param string $content Shortcode content
88 | *
89 | * @return string HTML shortcode output
90 | */
91 | public function get_rendered_shortcode( $atts, $content ) {
92 |
93 | $html = '';
94 |
95 | $default_atts = apply_filters( 'cpb_shortcode_default_atts', $this->default_settings, $atts, 'slide' );
96 |
97 | // Check default settings
98 | $atts = \shortcode_atts( $default_atts, $atts, 'slide' );
99 |
100 | $items = array();
101 |
102 | if ( ! empty( $atts['slide_type'] ) ) {
103 |
104 | switch ( $atts['slide_type'] ) {
105 |
106 | case 'custom':
107 | $items = $this->get_items_custom( $atts, $content );
108 | break;
109 | case 'feed':
110 | $items = $this->get_items_feed( $atts );
111 | break;
112 | case 'select':
113 | $items = $this->get_items_select( $atts );
114 | break;
115 | case 'remote_feed':
116 | $items = $this->get_items_remote( $atts );
117 | break;
118 | } // end switch
119 | } // end if
120 |
121 | if ( $items ) {
122 |
123 | global $cpb_slideshow;
124 |
125 | if ( empty( $cpb_slideshow ) ) {
126 |
127 | $cpb_slideshow = array(
128 | 'i' => 1,
129 | 'type' => 'gallery',
130 | );
131 |
132 | }
133 |
134 | switch ( $cpb_slideshow['type'] ) {
135 |
136 | case 'gallery':
137 | default:
138 | $html .= $this->get_gallery_slide_html( $items, $atts, $cpb_slideshow );
139 | break;
140 |
141 | } // end switch
142 | } // end if
143 |
144 | return $html;
145 |
146 | } // End get_rendered_shortcode
147 |
148 |
149 | public function get_gallery_slide_html( $items, $settings ) {
150 |
151 | global $cpb_slideshow;
152 |
153 | $html = '';
154 |
155 | foreach ( $items as $item ) {
156 |
157 | $active = ( 1 === $cpb_slideshow['i'] ) ? ' active-slide' : '';
158 | $bg_image = esc_url( $item['img'] );
159 | $img = '
';
160 | $link = ( $item['link'] ) ? '' : '';
161 | $title = $item['title'];
162 | $excerpt = wp_trim_words( $item['excerpt'], 35 );
163 |
164 | ob_start();
165 |
166 | include __DIR__ . '/slide.php';
167 |
168 | $html .= ob_get_clean();
169 |
170 | $cpb_slideshow['i'] = $cpb_slideshow['i'] + 1;
171 |
172 | } // end foreach
173 |
174 | return $html;
175 |
176 | } // end public
177 |
178 |
179 | protected function get_items_custom( $settings, $content ) {
180 |
181 | $promo_item = array();
182 |
183 | $promo_item['img'] = ( ! empty( $settings['img_src'] ) ) ? $settings['img_src'] : '';
184 |
185 | if ( ! empty( $settings['img_id'] ) ) {
186 |
187 | $image_array = cpb_get_image_properties_array( $settings['img_id'] );
188 |
189 | $promo_item['img_alt'] = $image_array['alt'];
190 |
191 | } else {
192 |
193 | $promo_item['img_alt'] = '';
194 |
195 | }// End if
196 |
197 | $promo_item['title'] = ( ! empty( $settings['item_title'] ) ) ? $settings['item_title'] : '';
198 |
199 | $promo_item['subtitle'] = ( ! empty( $settings['subtitle'] ) ) ? $settings['subtitle'] : '';
200 |
201 | $promo_item['excerpt'] = ( ! empty( $settings['excerpt'] ) ) ? $settings['excerpt'] : '';
202 |
203 | $promo_item['link'] = ( ! empty( $settings['link'] ) ) ? $settings['link'] : '';
204 |
205 | return array( $promo_item );
206 |
207 | } // end item_custom
208 |
209 | protected function get_items_feed( $settings ) {
210 |
211 | $query = cpb_get_query_class();
212 |
213 | $items = $query->get_local_items( $settings, '' );
214 |
215 | return $items;
216 |
217 | } // end item_feed
218 |
219 | protected function get_items_select( $settings ) {
220 |
221 | $query = cpb_get_query_class();
222 |
223 | $items = $query->get_remote_items( $settings, '' );
224 |
225 | return $items;
226 |
227 | } // end item_select
228 |
229 | protected function get_items_remote( $settings ) {
230 |
231 | $query = cpb_get_query_class();
232 |
233 | $items = $query->get_remote_items_feed( $settings, '' );
234 |
235 | return $items;
236 |
237 | }
238 |
239 |
240 | /*
241 | * @desc Get HTML for shortcode form
242 | * @since 3.0.0
243 | *
244 | * @param array $atts Shortcode attributes
245 | * @param string $content Shortcode content
246 | *
247 | * @return string HTML shortcode form output
248 | */
249 | public function get_shortcode_form( $id, $settings, $content, $cpb_form ) {
250 |
251 | $cpb_form = cpb_get_form_class();
252 |
253 | $custom_form = array(
254 | 'name' => cpb_get_input_name( $id, true, 'slide_type' ),
255 | 'value' => 'custom',
256 | 'selected' => $settings['slide_type'],
257 | 'title' => 'Custom',
258 | 'desc' => 'Add your own image & text',
259 | 'form' => $this->form_custom( $id, $settings, $cpb_form ),
260 | );
261 |
262 | $select_form = array(
263 | 'name' => cpb_get_input_name( $id, true, 'slide_type' ),
264 | 'value' => 'select',
265 | 'selected' => $settings['slide_type'],
266 | 'title' => 'Insert',
267 | 'desc' => 'Insert a specific post/page',
268 | 'form' => $cpb_form->get_form_select_post( cpb_get_input_name( $id, true ), $settings ),
269 | );
270 |
271 | $feed_form = array(
272 | 'name' => cpb_get_input_name( $id, true, 'slide_type' ),
273 | 'value' => 'feed',
274 | 'selected' => $settings['slide_type'],
275 | 'title' => 'Feed (This Site)',
276 | 'desc' => 'Load content by category or tag',
277 | 'form' => $cpb_form->get_form_local_query( cpb_get_input_name( $id, true ), $settings ),
278 | );
279 |
280 | $remote_feed_form = array(
281 | 'name' => cpb_get_input_name( $id, true, 'slide_type' ),
282 | 'value' => 'remote_feed',
283 | 'selected' => $settings['slide_type'],
284 | 'title' => 'Feed (Another Site)',
285 | 'desc' => 'Load external content by category or tag',
286 | 'form' => $cpb_form->get_form_remote_feed( cpb_get_input_name( $id, true ), $settings ),
287 | );
288 |
289 | $html = $cpb_form->multi_form( array( $custom_form, $select_form, $feed_form, $remote_feed_form ) );
290 |
291 | $display = $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'stack_vertical' ), 1, $settings['stack_vertical'], 'Stack Vertical' );
292 |
293 | $tags = $cpb_form->get_header_tags();
294 | unset( $tags['strong'] );
295 | $display .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'tag' ), $settings['tag'], $tags, 'Tag Type' );
296 |
297 | $img_ratio = array(
298 | 'spacer1x1' => 'Square',
299 | 'spacer3x4' => '3 x 4 ratio',
300 | 'spacer4x3' => '4 x 3 ratio',
301 | );
302 |
303 | $display .= $cpb_form->select_field( cpb_get_input_name( $id, true, 'img_ratio' ), $settings['img_ratio'], $img_ratio, 'Image Ratio' );
304 |
305 | $display .= '
';
306 |
307 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_img' ), 1, $settings['unset_img'], 'Hide Image' );
308 |
309 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_title' ), 1, $settings['unset_title'], 'Hide Title' );
310 |
311 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_excerpt' ), 1, $settings['unset_excerpt'], 'Hide Summary' );
312 |
313 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'unset_link' ), 1, $settings['unset_link'], 'Remove Link' );
314 |
315 | $display .= $cpb_form->checkbox_field( cpb_get_input_name( $id, true, 'as_lightbox' ), 1, $settings['as_lightbox'], 'Display Lightbox' );
316 |
317 | $adv = $cpb_form->text_field( cpb_get_input_name( $id, true, 'csshook' ), $settings['csshook'], 'CSS Hook' );
318 |
319 | return array( 'Source' => $html /*, 'Display' => $display, 'Advanced' => $adv */ );
320 |
321 | } // End get_shortcode_form
322 |
323 |
324 | protected function form_custom( $id, $settings, $cpb_form ) {
325 |
326 | $form = '
';
327 |
328 | $form .= $cpb_form->insert_media( cpb_get_input_name( $id, true ), $settings );
329 |
330 | $form .= '
';
331 |
332 | $form .= '
';
333 |
334 | $form .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'item_title' ), $settings['item_title'], 'Title', 'cpb-full-width' );
335 |
336 | $form .= $cpb_form->textarea_field( cpb_get_input_name( $id, true, 'excerpt' ), $settings['excerpt'], 'Summary/Text', 'cpb-full-width' );
337 |
338 | $form .= $cpb_form->text_field( cpb_get_input_name( $id, true, 'link' ), $settings['link'], 'Link', 'cpb-full-width' );
339 |
340 | $form .= '
';
341 |
342 | return $form;
343 |
344 | }
345 |
346 |
347 | } // End Slide
348 |
349 | $cpb_shortcode_slide = new Slide_Shortcode();
350 |
--------------------------------------------------------------------------------
/lib/classes/class-query.php:
--------------------------------------------------------------------------------
1 | fields;
19 |
20 | }
21 |
22 | public function get_local_items( $settings, $prefix = '', $fields = false ) {
23 |
24 | $items = array();
25 |
26 | if ( ! $fields ) {
27 |
28 | $fields = $this->get_fields();
29 |
30 | } // End if
31 |
32 | $query_args = $this->get_query_args( $settings, $prefix );
33 |
34 | $the_query = new \WP_Query( $query_args );
35 |
36 | if ( $the_query->have_posts() ) {
37 |
38 | while ( $the_query->have_posts() ) {
39 |
40 | $the_query->the_post();
41 |
42 | $item = array(
43 | 'event_date' => '',
44 | );
45 |
46 | if ( in_array( 'title', $fields, true ) ) {
47 |
48 | $item['title'] = get_the_title();
49 |
50 | }
51 |
52 | if ( in_array( 'content', $fields, true ) ) {
53 |
54 | $item['content'] = get_the_content();
55 |
56 | }
57 |
58 | if ( in_array( 'excerpt', $fields, true ) ) {
59 |
60 | $item['excerpt'] = $this->get_local_excerpt( $the_query->post->ID, $settings );
61 |
62 | }
63 |
64 | if ( in_array( 'img', $fields, true ) ) {
65 |
66 | $image = $this->get_local_image_array( $the_query->post->ID, $settings );
67 |
68 | $image = apply_filters( 'cpb_image_array', $image, $the_query->post->ID );
69 |
70 | $item['img'] = $image['src'];
71 |
72 | $item['img_alt'] = $image['alt'];
73 |
74 | } // End if
75 |
76 | if ( in_array( 'link', $fields, true ) ) {
77 |
78 | $item['link'] = \get_post_permalink();
79 |
80 | }
81 |
82 | $item = apply_filters( 'cpb_post_item_array_local_query', $item, $the_query->post );
83 |
84 | $items[ $the_query->post->ID ] = $item;
85 |
86 | } // end while
87 | } // end if
88 |
89 | return $items;
90 |
91 | }
92 |
93 | public function get_query_args( $settings, $prefix = '', $defaults = array() ) {
94 |
95 | $args = array();
96 |
97 | $args['post_type'] = ( ! empty( $settings[ $prefix . 'post_type' ] ) ) ? $settings[ $prefix . 'post_type' ] : 'post';
98 |
99 | $args['posts_per_page'] = ( ! empty( $settings[ $prefix . 'count' ] ) ) ? $settings[ $prefix . 'count' ] : 5;
100 |
101 | if ( ! empty( $settings[ $prefix . 'offset' ] ) ) {
102 |
103 | $args['offset'] = $settings[ $prefix . 'offset' ];
104 |
105 | } // end if
106 |
107 | if ( ! empty( $settings[ $prefix . 'order_by' ] ) ) {
108 |
109 | $args['orderby'] = $settings[ $prefix . 'order_by' ];
110 |
111 | } // end if
112 |
113 | if ( ! empty( $settings[ $prefix . 'order' ] ) ) {
114 |
115 | $args['order'] = $settings[ $prefix . 'order' ];
116 |
117 | } // end if
118 |
119 | // Handle Taxonomy Query
120 | if ( ! empty( $settings['taxonomy'] ) && ! empty( $settings['terms'] ) ) {
121 |
122 | $tax_query = array();
123 |
124 | $tax_query['taxonomy'] = $settings['taxonomy'];
125 |
126 | $tax_query['field'] = 'id';
127 |
128 | $terms = explode( ',', $settings['terms'] );
129 |
130 | foreach ( $terms as $term ) {
131 |
132 | $wp_term = \get_term_by( 'name', trim( $term ), $settings['taxonomy'] );
133 |
134 | //$tax_query['terms'][] = trim( $term );
135 |
136 | $tax_query['terms'][] = $wp_term->term_id;
137 |
138 | } // end foreach
139 |
140 | if ( ! empty( $settings['term_operator'] ) ) {
141 |
142 | $tax_query['operator'] = $settings['term_operator'];
143 |
144 | } // end if
145 |
146 | $args['tax_query'] = array( $tax_query );
147 |
148 | } // end if
149 |
150 | return $args;
151 |
152 | }
153 |
154 | protected function get_local_img( $post_id, $settings ) {
155 |
156 | $img_src = '';
157 |
158 | $img_id = \get_post_thumbnail_id( $post_id );
159 |
160 | if ( $img_id ) {
161 |
162 | $image = \wp_get_attachment_image_src( $img_id, 'single-post-thumbnail' );
163 |
164 | $img_src = $image[0];
165 |
166 | } // end if
167 |
168 | return $img_src;
169 |
170 | } // end get_local_img
171 |
172 |
173 | protected function get_local_image_array( $post_id, $settings ) {
174 |
175 | $image_array = array(
176 | 'alt' => '',
177 | 'src' => '',
178 | );
179 |
180 | $img_id = \get_post_thumbnail_id( $post_id );
181 |
182 | if ( $img_id ) {
183 |
184 | $image = \wp_get_attachment_image_src( $img_id, 'single-post-thumbnail' );
185 |
186 | $image_array['alt'] = \get_post_meta( $img_id, '_wp_attachment_image_alt', true );
187 |
188 | $image_array['src'] = $image[0];
189 |
190 | } // end if
191 |
192 | return $image_array;
193 |
194 | } // End get_local_image_array
195 |
196 | protected function get_local_excerpt( $post_id, $settings ) {
197 |
198 | // TO DO: Rewrite excerpt call here
199 | $excerpt = $this->get_excerpt_from_post_id( $post_id );
200 |
201 | return $excerpt;
202 |
203 | } // end get_local_excerpt
204 |
205 |
206 | /*
207 | * @desc Get the excerpt from the post
208 | * @since 0.0.3
209 | *
210 | * @param WP_Post $post WP Post object
211 | *
212 | * @return string Post excerpt
213 | */
214 | protected function get_excerpt_from_post_id( $post_id ) {
215 |
216 | $post = get_post( $post_id );
217 |
218 | // If this has an excerpt let's just use that
219 | if ( isset( $post->post_excerpt ) && ! empty( $post->post_excerpt ) ) {
220 |
221 | // bam done
222 | return $post->post_excerpt;
223 |
224 | } else { // OK so someone didn't set an excerpt, let's make one
225 |
226 | // We'll start with the post content
227 | $excerpt = $post->post_content;
228 |
229 | // Remove shortcodes but keep text inbetween ]...[/
230 | $excerpt = \preg_replace( '~(?:\[/?)[^/\]]+/?\]~s', '', $excerpt );
231 |
232 | // Remove HTML tags and script/style
233 | $excerpt = \wp_strip_all_tags( $excerpt );
234 |
235 | // Shorten to 35 words
236 | $excerpt = \wp_trim_words( $excerpt, 35 );
237 |
238 | return $excerpt;
239 |
240 | }// End if
241 |
242 | } // End get_excerpt_from_post
243 |
244 |
245 | public function get_remote_items( $settings, $prefix = '', $fields = false ) {
246 |
247 | if ( ! $fields ) {
248 |
249 | $fields = $this->get_fields();
250 |
251 | }
252 |
253 | $items = array();
254 |
255 | if ( is_array( $settings[ $prefix . 'remote_items' ] ) && ! empty( $settings[ $prefix . 'remote_items' ] ) ) {
256 |
257 | foreach ( $settings[ $prefix . 'remote_items' ] as $request_item ) {
258 |
259 | $url = $request_item['site'] . '/wp-json/posts/' . $request_item['id'];
260 |
261 | //var_dump( url );
262 |
263 | $response = \wp_remote_get( $url );
264 |
265 | if ( ! is_wp_error( $response ) ) {
266 |
267 | $body = \wp_remote_retrieve_body( $response );
268 |
269 | $json = \json_decode( $body, true );
270 |
271 | if ( $json ) {
272 |
273 | $item = array();
274 |
275 | if ( in_array( 'title', $fields, true ) ) {
276 |
277 | $item['title'] = $json['title'];
278 |
279 | }
280 |
281 | if ( in_array( 'content', $fields, true ) ) {
282 |
283 | $item['content'] = $json['content'];
284 |
285 | }
286 |
287 | if ( in_array( 'excerpt', $fields, true ) ) {
288 |
289 | $item['excerpt'] = $json['excerpt'];
290 |
291 | }
292 |
293 | if ( in_array( 'img', $fields, true ) ) {
294 |
295 | $item['img'] = $this->get_remote_img( $json, $settings );
296 |
297 | } // end if
298 |
299 | if ( in_array( 'link', $fields, true ) ) {
300 |
301 | $item['link'] = $json['link'];
302 |
303 | }
304 |
305 | $items[ $request_item['id'] ] = $item;
306 |
307 | //var_dump( $json['featured_image']['attachment_meta']['sizes'] );
308 |
309 | } // end if
310 | } // end if
311 | } // end foreach
312 | } // end if
313 |
314 | return $items;
315 |
316 | } // end get_remote_items
317 |
318 | public function get_remote_items_feed( $settings, $prefix = '', $fields = false ) {
319 |
320 | if ( ! $fields ) {
321 |
322 | $fields = $this->get_fields();
323 |
324 | }
325 |
326 | $items = array();
327 |
328 | if ( ! empty( $settings[ $prefix . 'site_url' ] ) ) {
329 |
330 | $query = $this->get_query_args_remote( $settings, '' );
331 |
332 | if ( $query ) {
333 |
334 | $url = $settings[ $prefix . 'site_url' ] . '/wp-json/posts' . $query;
335 |
336 | } else {
337 |
338 | $url = $settings[ $prefix . 'site_url' ];
339 |
340 | } // End if
341 |
342 | $response = \wp_remote_get( $url );
343 |
344 | if ( ! is_wp_error( $response ) ) {
345 |
346 | $body = \wp_remote_retrieve_body( $response );
347 |
348 | $json = \json_decode( $body, true );
349 |
350 | if ( $json ) {
351 |
352 | foreach ( $json as $json_item ) {
353 |
354 | $item = array();
355 |
356 | if ( in_array( 'title', $fields, true ) ) {
357 |
358 | $item['title'] = $json_item['title']['rendered'];
359 |
360 | }
361 |
362 | if ( in_array( 'content', $fields, true ) ) {
363 |
364 | $item['content'] = $json_item['content']['rendered'];
365 |
366 | }
367 |
368 | if ( in_array( 'excerpt', $fields, true ) ) {
369 |
370 | $item['excerpt'] = $json_item['excerpt']['rendered'];
371 |
372 | }
373 |
374 | if ( ! empty( $json_item['post_images'] ) ) {
375 |
376 | $item['img'] = $json_item['post_images']['full'];
377 |
378 | $item['images'] = $json_item['post_images'];
379 |
380 | } // End if
381 |
382 | if ( in_array( 'link', $fields, true ) ) {
383 |
384 | $item['link'] = $json_item['link'];
385 |
386 | }
387 |
388 | $items[ $json_item['id'] ] = $item;
389 |
390 | } // end foreach
391 | } // end if
392 | } // end if
393 | } // end if
394 |
395 | return $items;
396 |
397 | } // end get_remote_items
398 |
399 | protected function get_remote_img( $item, $settings, $prefix = '' ) {
400 |
401 | $size = ( ! empty( $settings[ $prefix . 'img_size' ] ) ) ? $settings[ $prefix . 'img_size' ] : 'medium';
402 |
403 | $url = '';
404 |
405 | if ( $item['featured_image'] ) {
406 |
407 | $sizes = $item['featured_image']['attachment_meta']['sizes'];
408 |
409 | if ( array_key_exists( $size, $sizes ) ) {
410 |
411 | $url = $sizes[ $size ]['url'];
412 |
413 | } // end if
414 | } // end if
415 |
416 | return $url;
417 |
418 | } // eng get_remote_img
419 |
420 | protected function get_query_args_remote( $settings, $prefix = '' ) {
421 |
422 | $get = '';
423 |
424 | $query = array();
425 |
426 | if ( ! empty( $settings[ $prefix . 'post_type' ] ) ) {
427 |
428 | $query[] = 'type=' . $settings[ $prefix . 'post_type' ];
429 |
430 | }
431 |
432 | if ( ! empty( $settings[ $prefix . 'taxonomy' ] ) ) {
433 |
434 | $query[] = 'filter[taxonomy]=' . $settings[ $prefix . 'taxonomy' ];
435 |
436 | }
437 |
438 | if ( ! empty( $settings[ $prefix . 'terms' ] ) ) {
439 |
440 | $query[] = 'filter[term]=' . $settings[ $prefix . 'terms' ];
441 |
442 | }
443 |
444 | if ( ! empty( $settings[ $prefix . 'count' ] ) ) {
445 |
446 | $query[] = 'filter[posts_per_page]=' . $settings[ $prefix . 'count' ];
447 |
448 | }
449 |
450 | if ( $query ) {
451 |
452 | $get = '?' . implode( '&', $query );
453 |
454 | } // end if
455 |
456 | return $get;
457 |
458 | } // end get_query_args_remote
459 |
460 | }
461 |
--------------------------------------------------------------------------------