vk-all-in-one-expansion-unit
Last commit date
_scss
10 years ago
bootstrap
10 years ago
css
10 years ago
images
10 years ago
js
10 years ago
languages
10 years ago
plugins
10 years ago
.gitignore
10 years ago
README.md
10 years ago
admin_wrapper.php
10 years ago
common_helpers.php
10 years ago
common_init.php
10 years ago
config.rb
10 years ago
gulpfile.js
10 years ago
package_manager.php
10 years ago
packages.php
10 years ago
readme.txt
10 years ago
screenshot-1.png
10 years ago
screenshot-2.png
10 years ago
vkExUnit.php
10 years ago
vkExUnit_admin.php
10 years ago
common_helpers.php
275 lines
| 1 | <?php |
| 2 | /*-------------------------------------------*/ |
| 3 | /* basic setting |
| 4 | /*-------------------------------------------*/ |
| 5 | /* Chack use post top page |
| 6 | /*-------------------------------------------*/ |
| 7 | /* Chack post type info |
| 8 | /*-------------------------------------------*/ |
| 9 | /* Head title |
| 10 | /*-------------------------------------------*/ |
| 11 | /* Page description |
| 12 | /*-------------------------------------------*/ |
| 13 | /* Archive title |
| 14 | /*-------------------------------------------*/ |
| 15 | |
| 16 | /*-------------------------------------------*/ |
| 17 | /* basic setting |
| 18 | /*-------------------------------------------*/ |
| 19 | function vkExUnit_get_name() { |
| 20 | $system_name = 'VK All in one Expansion Unit'; |
| 21 | return $system_name; |
| 22 | } |
| 23 | function vkExUnit_get_short_name() { |
| 24 | $short_name = 'VK'; |
| 25 | return $short_name; |
| 26 | } |
| 27 | function vkExUnit_get_capability_required(){ |
| 28 | $capability_required = 'activate_plugins'; |
| 29 | return $capability_required; |
| 30 | } |
| 31 | /*-------------------------------------------*/ |
| 32 | /* Chack use post top page |
| 33 | /*-------------------------------------------*/ |
| 34 | function vkExUnit_get_page_for_posts(){ |
| 35 | // Get post top page by setting display page. |
| 36 | $page_for_posts['post_top_id'] = get_option('page_for_posts'); |
| 37 | |
| 38 | // Set use post top page flag. |
| 39 | $page_for_posts['post_top_use'] = ( isset($page_for_posts['post_top_id']) && $page_for_posts['post_top_id'] ) ? true : false ; |
| 40 | |
| 41 | // When use post top page that get post top page name. |
| 42 | $page_for_posts['post_top_name'] = ( $page_for_posts['post_top_use'] ) ? get_the_title( $page_for_posts['post_top_id'] ) : ''; |
| 43 | |
| 44 | return $page_for_posts; |
| 45 | } |
| 46 | |
| 47 | /*-------------------------------------------*/ |
| 48 | /* Chack post type info |
| 49 | /*-------------------------------------------*/ |
| 50 | function vkExUnit_get_post_type(){ |
| 51 | |
| 52 | $page_for_posts = vkExUnit_get_page_for_posts(); |
| 53 | |
| 54 | // Get post type slug |
| 55 | /*-------------------------------------------*/ |
| 56 | $postType['slug'] = get_post_type(); |
| 57 | if ( !$postType['slug'] ) { |
| 58 | global $wp_query; |
| 59 | if ($wp_query->query_vars['post_type']) { |
| 60 | $postType['slug'] = $wp_query->query_vars['post_type']; |
| 61 | } else { |
| 62 | // Case of tax archive and no posts |
| 63 | $taxonomy = get_queried_object()->taxonomy; |
| 64 | $postType['slug'] = get_taxonomy( $taxonomy )->object_type[0]; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | // Get post type name |
| 69 | /*-------------------------------------------*/ |
| 70 | $post_type_object = get_post_type_object($postType['slug']); |
| 71 | if($post_type_object){ |
| 72 | if ( $page_for_posts['post_top_use'] && $postType['slug'] == 'post' ){ |
| 73 | $postType['name'] = esc_html( get_the_title($page_for_posts['post_top_id']) ); |
| 74 | } else { |
| 75 | $postType['name'] = esc_html($post_type_object->labels->name); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | // Get post type archive url |
| 80 | /*-------------------------------------------*/ |
| 81 | if ( $page_for_posts['post_top_use'] && $postType['slug'] == 'post' ){ |
| 82 | $postType['url'] = get_the_permalink($page_for_posts['post_top_id']); |
| 83 | } else { |
| 84 | $postType['url'] = home_url().'/?post_type='.$postType['slug']; |
| 85 | } |
| 86 | |
| 87 | $postType = apply_filters('vkExUnit_postType_custom',$postType); |
| 88 | return $postType; |
| 89 | } |
| 90 | /*-------------------------------------------*/ |
| 91 | /* Head title |
| 92 | /*-------------------------------------------*/ |
| 93 | function vkExUnit_get_wp_head_title(){ |
| 94 | global $wp_query; |
| 95 | $post = $wp_query->get_queried_object(); |
| 96 | $sep = ' | '; |
| 97 | $sep = apply_filters( 'vkExUnit_get_wp_head_title', $sep ); |
| 98 | |
| 99 | if (is_front_page()) { |
| 100 | $title = get_bloginfo('name'); |
| 101 | } else if ( is_home() && !is_front_page()) { |
| 102 | $title = vkExUnit_get_the_archive_title().$sep.get_bloginfo('name'); |
| 103 | } else if ( is_archive() ) { |
| 104 | $title = vkExUnit_get_the_archive_title().$sep.get_bloginfo('name'); |
| 105 | // Page |
| 106 | } else if (is_page()) { |
| 107 | // Sub Pages |
| 108 | if ( $post->post_parent ) { |
| 109 | if($post->ancestors){ |
| 110 | foreach($post->ancestors as $post_anc_id){ |
| 111 | $post_id = $post_anc_id; |
| 112 | } |
| 113 | } else { |
| 114 | $post_id = $post->ID; |
| 115 | } |
| 116 | $title = get_the_title().$sep.get_the_title($post_id).$sep.get_bloginfo('name'); |
| 117 | // Not Sub Pages |
| 118 | } else { |
| 119 | $title = get_the_title().$sep.get_bloginfo('name'); |
| 120 | } |
| 121 | } else if ( is_single() || is_attachment() ){ |
| 122 | $title = get_the_title().$sep.get_bloginfo('name'); |
| 123 | |
| 124 | // Search |
| 125 | } else if ( is_search() ){ |
| 126 | $title = sprintf(__('Search Results for : %s', 'vkExUnit'),get_search_query()).$sep.get_bloginfo('name'); |
| 127 | // 404 |
| 128 | } else if (is_404()){ |
| 129 | $title = __('Not found', 'vkExUnit').$sep.get_bloginfo('name'); |
| 130 | // Other |
| 131 | } else { |
| 132 | $title = get_bloginfo('name'); |
| 133 | } |
| 134 | |
| 135 | // Add Page numner. |
| 136 | global $paged; |
| 137 | if ( $paged >= 2 ){ |
| 138 | $title = '['.sprintf(__('Page of %s', 'vkExUnit' ),$paged).'] '.$title; |
| 139 | } |
| 140 | |
| 141 | $title = apply_filters( 'vkExUnit_get_wp_head_title', $title ); |
| 142 | |
| 143 | // Remove Tags(ex:<i>) & return |
| 144 | return strip_tags($title); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /*-------------------------------------------*/ |
| 149 | /* Page description |
| 150 | /*-------------------------------------------*/ |
| 151 | function vkExUnit_get_pageDescription() { |
| 152 | global $wp_query; |
| 153 | $post = $wp_query->get_queried_object(); |
| 154 | if ( is_front_page() ) { |
| 155 | if ( isset($post->post_excerpt) && $post->post_excerpt ) { |
| 156 | $pageDescription = get_the_excerpt(); |
| 157 | } else { |
| 158 | $pageDescription = get_bloginfo( 'description' ); |
| 159 | } |
| 160 | } else if ( is_home() ) { |
| 161 | $page_for_posts = vkExUnit_get_page_for_posts(); |
| 162 | if ( $page_for_posts['post_top_use'] ){ |
| 163 | $page = get_post($page_for_posts['post_top_id']); |
| 164 | $pageDescription = $page->post_excerpt; |
| 165 | } else { |
| 166 | $pageDescription = get_bloginfo( 'description' ); |
| 167 | } |
| 168 | } else if (is_category() || is_tax()) { |
| 169 | if ( ! $post->description ) { |
| 170 | $pageDescription = sprintf(__('About %s', 'vkExUnit'),single_cat_title('',false)).' '.get_bloginfo('name').' '.get_bloginfo('description'); |
| 171 | } else { |
| 172 | $pageDescription = $post->description; |
| 173 | } |
| 174 | } else if (is_tag()) { |
| 175 | $pageDescription = strip_tags(tag_description()); |
| 176 | $pageDescription = str_replace(array("\r\n","\r","\n"), '', $pageDescription); // delete br |
| 177 | if ( ! $pageDescription ) { |
| 178 | $pageDescription = sprintf(__('About %s', 'vkExUnit'),single_tag_title('',false)).' '.get_bloginfo('name').' '.get_bloginfo('description'); |
| 179 | } |
| 180 | } else if (is_archive()) { |
| 181 | if (is_year()){ |
| 182 | $description_date = get_the_date( _x( 'Y', 'yearly archives date format', 'vkExUnit' ) ); |
| 183 | $pageDescription = sprintf(_x('Article of %s.','Yearly archive description', 'vkExUnit'), $description_date ); |
| 184 | $pageDescription .= ' '.get_bloginfo('name').' '.get_bloginfo('description'); |
| 185 | } else if (is_month()){ |
| 186 | $description_date = get_the_date( _x( 'F Y', 'monthly archives date format', 'vkExUnit' ) ); |
| 187 | $pageDescription = sprintf(_x('Article of %s.','Archive description', 'vkExUnit'),$description_date ); |
| 188 | $pageDescription .= ' '.get_bloginfo('name').' '.get_bloginfo('description'); |
| 189 | } else if (is_author()) { |
| 190 | $userObj = get_queried_object(); |
| 191 | $pageDescription = sprintf(_x('Article of %s.','Archive description', 'vkExUnit'),esc_html($userObj->display_name) ); |
| 192 | $pageDescription .= ' '.get_bloginfo('name').' '.get_bloginfo('description'); |
| 193 | } else { |
| 194 | $postType = get_post_type(); |
| 195 | $pageDescription = sprintf(_x('Article of %s.','Archive description', 'vkExUnit'),esc_html(get_post_type_object($postType)->labels->name) ); |
| 196 | $pageDescription .= ' '.get_bloginfo('name').' '.get_bloginfo('description'); |
| 197 | } |
| 198 | } else if (is_page() || is_single()) { |
| 199 | $metaExcerpt = $post->post_excerpt; |
| 200 | if ($metaExcerpt) { |
| 201 | $pageDescription = $metaExcerpt; |
| 202 | } else { |
| 203 | $pageDescription = mb_substr( strip_tags($post->post_content), 0, 240 ); // kill tags and trim 240 chara |
| 204 | } |
| 205 | } else { |
| 206 | $pageDescription = get_bloginfo('description'); |
| 207 | } |
| 208 | global $paged; |
| 209 | if ( $paged != '0'){ |
| 210 | $pageDescription = '['.sprintf(__('Page of %s', 'vkExUnit' ),$paged).'] '.$pageDescription; |
| 211 | } |
| 212 | $pageDescription = apply_filters( 'vkExUnit_pageDescriptionCustom', $pageDescription ); |
| 213 | $pageDescription = esc_html(strip_tags($pageDescription)); |
| 214 | // Delete Line break |
| 215 | $pageDescription = str_replace(array("\r", "\n"), ' ', $pageDescription); |
| 216 | return $pageDescription; |
| 217 | } |
| 218 | |
| 219 | /*-------------------------------------------*/ |
| 220 | /* Archive title |
| 221 | /*-------------------------------------------*/ |
| 222 | |
| 223 | function vkExUnit_get_the_archive_title(){ |
| 224 | if ( is_category() ) { |
| 225 | $title = single_cat_title( '', false ); |
| 226 | } elseif ( is_tag() ) { |
| 227 | $title = single_tag_title( '', false ); |
| 228 | } elseif ( is_author() ) { |
| 229 | $title = sprintf( __( 'Author: %s', 'vkExUnit' ), '<span class="vcard">' . get_the_author() . '</span>' ); |
| 230 | } elseif ( is_year() ) { |
| 231 | $title = get_the_date( _x( 'Y', 'yearly archives date format', 'vkExUnit' ) ); |
| 232 | } elseif ( is_month() ) { |
| 233 | $title = get_the_date( _x( 'F Y', 'monthly archives date format', 'vkExUnit' ) ); |
| 234 | } elseif ( is_day() ) { |
| 235 | $title = get_the_date( _x( 'F j, Y', 'daily archives date format', 'vkExUnit' ) ); |
| 236 | } elseif ( is_tax( 'post_format' ) ) { |
| 237 | if ( is_tax( 'post_format', 'post-format-aside' ) ) { |
| 238 | $title = _x( 'Asides', 'post format archive title' ); |
| 239 | } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) { |
| 240 | $title = _x( 'Galleries', 'post format archive title' ); |
| 241 | } elseif ( is_tax( 'post_format', 'post-format-image' ) ) { |
| 242 | $title = _x( 'Images', 'post format archive title' ); |
| 243 | } elseif ( is_tax( 'post_format', 'post-format-video' ) ) { |
| 244 | $title = _x( 'Videos', 'post format archive title' ); |
| 245 | } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) { |
| 246 | $title = _x( 'Quotes', 'post format archive title' ); |
| 247 | } elseif ( is_tax( 'post_format', 'post-format-link' ) ) { |
| 248 | $title = _x( 'Links', 'post format archive title' ); |
| 249 | } elseif ( is_tax( 'post_format', 'post-format-status' ) ) { |
| 250 | $title = _x( 'Statuses', 'post format archive title' ); |
| 251 | } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) { |
| 252 | $title = _x( 'Audio', 'post format archive title' ); |
| 253 | } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) { |
| 254 | $title = _x( 'Chats', 'post format archive title' ); |
| 255 | } |
| 256 | } elseif ( is_post_type_archive() ) { |
| 257 | $title = post_type_archive_title( '', false ); |
| 258 | } elseif ( is_tax() ) { |
| 259 | $title = single_term_title( '', false ); |
| 260 | } elseif ( is_home() && !is_front_page() ){ |
| 261 | $vkExUnit_page_for_posts = vkExUnit_get_page_for_posts(); |
| 262 | $title = $vkExUnit_page_for_posts['post_top_name']; |
| 263 | } else { |
| 264 | global $wp_query; |
| 265 | // get post type |
| 266 | $postType = $wp_query->query_vars['post_type']; |
| 267 | if ( $postType ) { |
| 268 | $title = get_post_type_object($postType)->labels->name; |
| 269 | } else { |
| 270 | $title = __( 'Archives', 'vkExUnit' ); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | return apply_filters( 'vkExUnit_get_the_archive_title', $title ); |
| 275 | } |