|
20 | 20 | namespace ithoughts\tooltip_glossary\shortcode;
|
21 | 21 |
|
22 | 22 | if ( ! defined( 'ABSPATH' ) ) {
|
23 |
| - status_header( 403 );wp_die("Forbidden");// Exit if accessed directly |
| 23 | + status_header( 403 );wp_die("Forbidden");// Exit if accessed directly |
24 | 24 | }
|
25 | 25 |
|
26 | 26 | if ( ! class_exists( __NAMESPACE__ . '\\TermList' ) ) {
|
@@ -68,148 +68,148 @@ public function glossary_term_list( $atts, $content = '' ) {
|
68 | 68 | default:{
|
69 | 69 | $mode = self::LIST_MODE_NONE;
|
70 | 70 | }
|
| 71 | + } |
| 72 | + |
| 73 | + // Sanity check the list of letters (if set by user). |
| 74 | + $alphas = $this->filter_alphas_to_array( isset( $data['handled'] ) && isset( $data['handled']['alpha'] ) && $data['handled']['alpha'] ? $data['handled']['alpha'] : null ); |
| 75 | + // Checks for partial listing options (on first letter, or group) |
| 76 | + $group_ids = $this->filter_groupIds_to_array( isset( $data['handled'] ) && isset( $data['handled']['group'] ) ? $data['handled']['group'] : null ); |
| 77 | + |
| 78 | + $terms; |
| 79 | + $count; |
| 80 | + |
| 81 | + // Define default desc to none. Will generate a simple link |
| 82 | + // If no content is required, use microposts. Else, use normal terms |
| 83 | + if ( $mode & self::LIST_MODE_MICROPOST ) { |
| 84 | + // Add qtip script only if loading tooltips |
| 85 | + if ( $mode === self::LIST_MODE_TIP ) { |
| 86 | + \ithoughts\tooltip_glossary\Backbone::get_instance()->add_script( 'qtip' ); |
71 | 87 | }
|
72 | 88 |
|
73 |
| - // Sanity check the list of letters (if set by user). |
74 |
| - $alphas = $this->filter_alphas_to_array( isset( $data['handled'] ) && isset( $data['handled']['alpha'] ) && $data['handled']['alpha'] ? $data['handled']['alpha'] : null ); |
75 |
| - // Checks for partial listing options (on first letter, or group) |
76 |
| - $group_ids = $this->filter_groupIds_to_array( isset( $data['handled'] ) && isset( $data['handled']['group'] ) ? $data['handled']['group'] : null ); |
77 |
| - |
78 |
| - $terms; |
79 |
| - $count; |
80 |
| - |
81 |
| - // Define default desc to none. Will generate a simple link |
82 |
| - // If no content is required, use microposts. Else, use normal terms |
83 |
| - if ( $mode & self::LIST_MODE_MICROPOST ) { |
84 |
| - // Add qtip script only if loading tooltips |
85 |
| - if ( $mode === self::LIST_MODE_TIP ) { |
86 |
| - \ithoughts\tooltip_glossary\Backbone::get_instance()->add_script( 'qtip' ); |
87 |
| - } |
88 |
| - |
89 |
| - // Fetch microposts |
90 |
| - $termsInfos = $this->get_microposts( $group_ids,$alphas ); |
91 |
| - } else { |
92 |
| - // Fetch full posts |
93 |
| - $linkdata = apply_filters( 'ithoughts_tt_gl-split-args', $linkdata ); |
94 |
| - $termsInfos = $this->get_lists_terms( $group_ids,$alphas ); |
95 |
| - } |
96 |
| - |
97 |
| - $terms = $this->dispatch_per_char( $termsInfos['terms'], 0, 'WP_Post' ); |
98 |
| - $count = $termsInfos['count']; |
99 |
| - |
100 |
| - // Go through all glossaries, and restrict to alpha list if supplied. |
101 |
| - $lists = array(); |
102 |
| - $countItems = 0; |
103 |
| - foreach ( $terms as $char => $terms_char ) { |
104 |
| - if ( count( $alphas ) == 0 || in_array( $char, $alphas ) ) { |
105 |
| - $lists[] = "<li class=\"glossary-item-header\">$char</li>"; |
| 89 | + // Fetch microposts |
| 90 | + $termsInfos = $this->get_microposts( $group_ids,$alphas ); |
| 91 | + } else { |
| 92 | + // Fetch full posts |
| 93 | + $linkdata = apply_filters( 'ithoughts_tt_gl-split-args', $linkdata ); |
| 94 | + $termsInfos = $this->get_lists_terms( $group_ids,$alphas ); |
| 95 | + } |
| 96 | + |
| 97 | + $terms = $this->dispatch_per_char( $termsInfos['terms'], 0, 'WP_Post' ); |
| 98 | + $count = $termsInfos['count']; |
| 99 | + |
| 100 | + // Go through all glossaries, and restrict to alpha list if supplied. |
| 101 | + $lists = array(); |
| 102 | + $countItems = 0; |
| 103 | + foreach ( $terms as $char => $terms_char ) { |
| 104 | + if ( count( $alphas ) == 0 || in_array( $char, $alphas ) ) { |
| 105 | + $lists[] = "<li class=\"glossary-item-header\">$char</li>"; |
| 106 | + $countItems++; |
| 107 | + |
| 108 | + foreach ( $terms_char as $term ) { |
106 | 109 | $countItems++;
|
107 |
| - |
108 |
| - foreach ( $terms_char as $term ) { |
109 |
| - $countItems++; |
110 |
| - $term_standardized_post; // If only microposts were retrieved, cast them in WP_Post (usable by standard methods) |
111 |
| - if ( $mode & self::LIST_MODE_MICROPOST ) { |
112 |
| - $term_standardized_post = $term->to_WP_Post(); |
113 |
| - } else { |
114 |
| - $term_standardized_post = &$term; |
115 |
| - } |
116 |
| - $linkAttrs = (isset( $linkdata['linkAttrs'] ) && is_array( $linkdata['linkAttrs'] )) ? $linkdata['linkAttrs'] : $linkdata; |
117 |
| - $linkAttrs['title'] = esc_attr( $term_standardized_post->post_title ); |
118 |
| - $linkAttrs['alt'] = esc_attr( $term_standardized_post->post_title ); |
119 |
| - |
120 |
| - $link = ''; |
121 |
| - $content = ''; |
122 |
| - switch ( $mode ) { |
123 |
| - case self::LIST_MODE_NONE:{ |
124 |
| - $href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) ); |
125 |
| - $target = ''; |
126 |
| - if ( $data['options']['termlinkopt'] != 'none' ) { |
127 |
| - $linkAttrs['target'] = '_blank'; |
128 |
| - } |
129 |
| - $linkAttrs['href'] = &$href; |
130 |
| - $args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs ); |
131 |
| - $link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>'; |
132 |
| - }break; |
133 |
| - |
134 |
| - case self::LIST_MODE_TIP:{ |
135 |
| - $link = apply_filters( 'ithoughts_tt_gl_get_glossary_term_element', $term_standardized_post, null, $linkdata ); |
136 |
| - } break; |
137 |
| - |
138 |
| - case self::LIST_MODE_EXCERPT:{ |
139 |
| - $href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) ); |
140 |
| - $target = ''; |
141 |
| - if ( $data['options']['termlinkopt'] != 'none' ) { |
142 |
| - $linkAttrs['target'] = '_blank'; |
143 |
| - } |
144 |
| - $linkAttrs['href'] = &$href; |
145 |
| - $args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs ); |
146 |
| - $link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>'; |
147 |
| - $content = '<br>' . '<span class="glossary-item-desc">' . apply_filters( 'ithoughts_tt_gl-term-excerpt', $term_standardized_post ) . '</span>'; |
148 |
| - } break; |
149 |
| - |
150 |
| - case self::LIST_MODE_FULL:{ |
151 |
| - $href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) ); |
152 |
| - $target = ''; |
153 |
| - if ( $data['options']['termlinkopt'] != 'none' ) { |
154 |
| - $linkAttrs['target'] = '_blank'; |
155 |
| - } |
156 |
| - $linkAttrs['href'] = &$href; |
157 |
| - $args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs ); |
158 |
| - $link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>'; |
159 |
| - $content = '<br>' . '<span class="glossary-item-desc">' . $term->post_content . '</span>'; |
160 |
| - } break; |
161 |
| - }// End switch(). |
162 |
| - |
163 |
| - $lists[] = "<li class=\"glossary-item\">$link$content</li>"; |
164 |
| - }// End foreach(). |
165 |
| - }// End if(). |
166 |
| - }// End foreach(). |
167 |
| - if ( ! isset( $data['handled']['cols'] ) || $data['handled']['cols'] == 0 || $data['handled']['cols'] === false ) { |
168 |
| - $data['handled']['cols'] = 1; // set col size to all items |
| 110 | + $term_standardized_post; // If only microposts were retrieved, cast them in WP_Post (usable by standard methods) |
| 111 | + if ( $mode & self::LIST_MODE_MICROPOST ) { |
| 112 | + $term_standardized_post = $term->to_WP_Post(); |
| 113 | + } else { |
| 114 | + $term_standardized_post = &$term; |
| 115 | + } |
| 116 | + $linkAttrs = (isset( $linkdata['linkAttrs'] ) && is_array( $linkdata['linkAttrs'] )) ? $linkdata['linkAttrs'] : $linkdata; |
| 117 | + $linkAttrs['title'] = esc_attr( $term_standardized_post->post_title ); |
| 118 | + $linkAttrs['alt'] = esc_attr( $term_standardized_post->post_title ); |
| 119 | + |
| 120 | + $link = ''; |
| 121 | + $content = ''; |
| 122 | + switch ( $mode ) { |
| 123 | + case self::LIST_MODE_NONE:{ |
| 124 | + $href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) ); |
| 125 | + $target = ''; |
| 126 | + if ( $data['options']['termlinkopt'] != 'none' ) { |
| 127 | + $linkAttrs['target'] = '_blank'; |
| 128 | + } |
| 129 | + $linkAttrs['href'] = &$href; |
| 130 | + $args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs ); |
| 131 | + $link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>'; |
| 132 | + }break; |
| 133 | + |
| 134 | + case self::LIST_MODE_TIP:{ |
| 135 | + $link = apply_filters( 'ithoughts_tt_gl_get_glossary_term_element', $term_standardized_post, null, $linkdata ); |
| 136 | + } break; |
| 137 | + |
| 138 | + case self::LIST_MODE_EXCERPT:{ |
| 139 | + $href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) ); |
| 140 | + $target = ''; |
| 141 | + if ( $data['options']['termlinkopt'] != 'none' ) { |
| 142 | + $linkAttrs['target'] = '_blank'; |
| 143 | + } |
| 144 | + $linkAttrs['href'] = &$href; |
| 145 | + $args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs ); |
| 146 | + $link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>'; |
| 147 | + $content = '<br>' . '<span class="glossary-item-desc">' . apply_filters( 'ithoughts_tt_gl-term-excerpt', $term_standardized_post ) . '</span>'; |
| 148 | + } break; |
| 149 | + |
| 150 | + case self::LIST_MODE_FULL:{ |
| 151 | + $href = apply_filters( 'ithoughts_tt_gl_term_link', \ithoughts\v5_0\Toolbox::get_permalink_light( $term_standardized_post, 'glossary' ) ); |
| 152 | + $target = ''; |
| 153 | + if ( $data['options']['termlinkopt'] != 'none' ) { |
| 154 | + $linkAttrs['target'] = '_blank'; |
| 155 | + } |
| 156 | + $linkAttrs['href'] = &$href; |
| 157 | + $args = \ithoughts\v5_0\Toolbox::concat_attrs( $linkAttrs ); |
| 158 | + $link = '<a ' . $args . '>' . $term_standardized_post->post_title . '</a>'; |
| 159 | + $content = '<br>' . '<span class="glossary-item-desc">' . do_shortcode($term->post_content) . '</span>'; |
| 160 | + } break; |
| 161 | + }// End switch(). |
| 162 | + |
| 163 | + $lists[] = "<li class=\"glossary-item\">$link$content</li>"; |
| 164 | + }// End foreach(). |
| 165 | + }// End if(). |
| 166 | + }// End foreach(). |
| 167 | + if ( ! isset( $data['handled']['cols'] ) || $data['handled']['cols'] == 0 || $data['handled']['cols'] === false ) { |
| 168 | + $data['handled']['cols'] = 1; // set col size to all items |
| 169 | + } |
| 170 | + $chunked; |
| 171 | + if ( $data['handled']['cols'] != 1 ) { |
| 172 | + $termsPerChunkFloat = $countItems / $data['handled']['cols']; |
| 173 | + $termsPerChunk = intval( $termsPerChunkFloat ); |
| 174 | + if ( $termsPerChunkFloat != $termsPerChunk ) { |
| 175 | + $termsPerChunk++; |
169 | 176 | }
|
170 |
| - $chunked; |
171 |
| - if ( $data['handled']['cols'] != 1 ) { |
172 |
| - $termsPerChunkFloat = $countItems / $data['handled']['cols']; |
173 |
| - $termsPerChunk = intval( $termsPerChunkFloat ); |
174 |
| - if ( $termsPerChunkFloat != $termsPerChunk ) { |
175 |
| - $termsPerChunk++; |
176 |
| - } |
177 | 177 |
|
178 |
| - if ( $termsPerChunk < 1 ) { |
179 |
| - $termsPerChunk = 1; |
180 |
| - } |
181 |
| - $chunked = array_chunk( $lists, $termsPerChunk ); |
182 |
| - } else { |
183 |
| - $chunked = array( &$lists ); |
| 178 | + if ( $termsPerChunk < 1 ) { |
| 179 | + $termsPerChunk = 1; |
184 | 180 | }
|
| 181 | + $chunked = array_chunk( $lists, $termsPerChunk ); |
| 182 | + } else { |
| 183 | + $chunked = array( &$lists ); |
| 184 | + } |
185 | 185 |
|
186 |
| - $data['attributes']['class'] = 'glossary-list-details' . ((isset( $data['attributes']['class'] ) && $data['attributes']['class']) ? ' ' . $data['attributes']['class'] : ''); |
187 |
| - /* |
| 186 | + $data['attributes']['class'] = 'glossary-list-details' . ((isset( $data['attributes']['class'] ) && $data['attributes']['class']) ? ' ' . $data['attributes']['class'] : ''); |
| 187 | + /* |
188 | 188 | if(isset($data["handled"]["masonry"])){
|
189 | 189 | $data["attributes"]["class"] .= " masonry";
|
190 | 190 | $data["attributes"]["class"] = trim($data["attributes"]["class"]);
|
191 | 191 | $data["attributes"]["data-cols"] = $data["handled"]["cols"];
|
192 | 192 | }*/
|
193 |
| - $args = \ithoughts\v5_0\Toolbox::concat_attrs( $data['attributes'] ); |
| 193 | + $args = \ithoughts\v5_0\Toolbox::concat_attrs( $data['attributes'] ); |
194 | 194 |
|
195 |
| - $return = '<div ' . $args . '>'; |
196 |
| - if ( isset( $data['handled']['masonry'] ) ) {/* |
| 195 | + $return = '<div ' . $args . '>'; |
| 196 | + if ( isset( $data['handled']['masonry'] ) ) {/* |
197 | 197 | \ithoughts\tooltip_glossary\Backbone::get_instance()->add_script('list');
|
198 | 198 | $return .= '<ul class="glossary-list">';
|
199 | 199 | foreach( $chunked as $col => $items ){
|
200 | 200 | $return .= implode( '', $items );
|
201 | 201 | }
|
202 | 202 | $return .= '</ul>';*/
|
203 |
| - } else { |
204 |
| - foreach ( $chunked as $col => $items ) { |
205 |
| - $return .= '<ul class="glossary-list">'; |
206 |
| - $return .= implode( '', $items ); |
207 |
| - $return .= '</ul>'; |
208 |
| - } |
| 203 | + } else { |
| 204 | + foreach ( $chunked as $col => $items ) { |
| 205 | + $return .= '<ul class="glossary-list">'; |
| 206 | + $return .= implode( '', $items ); |
| 207 | + $return .= '</ul>'; |
209 | 208 | }
|
210 |
| - $return .= '</div>'; |
| 209 | + } |
| 210 | + $return .= '</div>'; |
211 | 211 |
|
212 |
| - return $return; |
| 212 | + return $return; |
213 | 213 | } // glossary_term_list
|
214 | 214 | } // termlist
|
215 | 215 | }// End if().
|
0 commit comments