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
plugins_admin
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
compile.bat
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
uninstaller.php
10 years ago
vkExUnit.php
10 years ago
vkExUnit_admin.php
10 years ago
common_helpers.php
234 lines
| 1 | <?php |
| 2 | /*-------------------------------------------*/ |
| 3 | /* basic setting |
| 4 | /*-------------------------------------------*/ |
| 5 | /* Chack use post top page |
| 6 | /*-------------------------------------------*/ |
| 7 | /* Chack post type info |
| 8 | /*-------------------------------------------*/ |
| 9 | /* Page description |
| 10 | /*-------------------------------------------*/ |
| 11 | /* Archive title |
| 12 | /*-------------------------------------------*/ |
| 13 | |
| 14 | /*-------------------------------------------*/ |
| 15 | /* basic setting |
| 16 | /*-------------------------------------------*/ |
| 17 | function vkExUnit_get_name() { |
| 18 | $system_name = apply_filters( 'vkExUnit_get_name_custom','VK All in one Expansion Unit' ); |
| 19 | return $system_name; |
| 20 | } |
| 21 | function vkExUnit_get_little_short_name() { |
| 22 | $little_short_name = apply_filters( 'vkExUnit_get_little_short_name_custom','VK ExUnit' ); |
| 23 | return $little_short_name; |
| 24 | } |
| 25 | function vkExUnit_get_short_name() { |
| 26 | $short_name = apply_filters( 'vkExUnit_get_short_name_custom','VK' ); |
| 27 | return $short_name; |
| 28 | } |
| 29 | function vkExUnit_get_capability_required() { |
| 30 | $capability_required = 'activate_plugins'; |
| 31 | return $capability_required; |
| 32 | } |
| 33 | function vkExUnit_get_systemlogo() { |
| 34 | $logo = '<div class="logo_exUnit">'; |
| 35 | $logo .= '<img src="' . apply_filters( 'vkExUnit_news_image_URL_small', vkExUnit_get_directory_uri( '/images/head_logo_ExUnit.png' ) ) . '" alt="VK ExUnit" />'; |
| 36 | $logo .= '</div>'; |
| 37 | return $logo; |
| 38 | } |
| 39 | |
| 40 | /*-------------------------------------------*/ |
| 41 | /* Chack use post top page |
| 42 | /*-------------------------------------------*/ |
| 43 | function vkExUnit_get_page_for_posts() { |
| 44 | // Get post top page by setting display page. |
| 45 | $page_for_posts['post_top_id'] = get_option( 'page_for_posts' ); |
| 46 | |
| 47 | // Set use post top page flag. |
| 48 | $page_for_posts['post_top_use'] = ( isset( $page_for_posts['post_top_id'] ) && $page_for_posts['post_top_id'] ) ? true : false ; |
| 49 | |
| 50 | // When use post top page that get post top page name. |
| 51 | $page_for_posts['post_top_name'] = ( $page_for_posts['post_top_use'] ) ? get_the_title( $page_for_posts['post_top_id'] ) : ''; |
| 52 | |
| 53 | return $page_for_posts; |
| 54 | } |
| 55 | |
| 56 | /*-------------------------------------------*/ |
| 57 | /* Chack post type info |
| 58 | /*-------------------------------------------*/ |
| 59 | function vkExUnit_get_post_type() { |
| 60 | |
| 61 | $page_for_posts = vkExUnit_get_page_for_posts(); |
| 62 | |
| 63 | // Get post type slug |
| 64 | /*-------------------------------------------*/ |
| 65 | $postType['slug'] = get_post_type(); |
| 66 | if ( ! $postType['slug'] ) { |
| 67 | global $wp_query; |
| 68 | if ( $wp_query->query_vars['post_type'] ) { |
| 69 | $postType['slug'] = $wp_query->query_vars['post_type']; |
| 70 | } else { |
| 71 | // Case of tax archive and no posts |
| 72 | $taxonomy = get_queried_object()->taxonomy; |
| 73 | $postType['slug'] = get_taxonomy( $taxonomy )->object_type[0]; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Get post type name |
| 78 | /*-------------------------------------------*/ |
| 79 | $post_type_object = get_post_type_object( $postType['slug'] ); |
| 80 | if ( $post_type_object ) { |
| 81 | if ( $page_for_posts['post_top_use'] && $postType['slug'] == 'post' ) { |
| 82 | $postType['name'] = esc_html( get_the_title( $page_for_posts['post_top_id'] ) ); |
| 83 | } else { |
| 84 | $postType['name'] = esc_html( $post_type_object->labels->name ); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // Get post type archive url |
| 89 | /*-------------------------------------------*/ |
| 90 | if ( $page_for_posts['post_top_use'] && $postType['slug'] == 'post' ) { |
| 91 | $postType['url'] = get_the_permalink( $page_for_posts['post_top_id'] ); |
| 92 | } else { |
| 93 | $postType['url'] = home_url().'/?post_type='.$postType['slug']; |
| 94 | } |
| 95 | |
| 96 | $postType = apply_filters( 'vkExUnit_postType_custom',$postType ); |
| 97 | return $postType; |
| 98 | } |
| 99 | |
| 100 | /*-------------------------------------------*/ |
| 101 | /* Archive title |
| 102 | /*-------------------------------------------*/ |
| 103 | function vkExUnit_get_the_archive_title() { |
| 104 | if ( is_category() ) { |
| 105 | $title = single_cat_title( '', false ); |
| 106 | } elseif ( is_tag() ) { |
| 107 | $title = single_tag_title( '', false ); |
| 108 | } elseif ( is_author() ) { |
| 109 | $title = sprintf( __( 'Author: %s', 'vkExUnit' ), '<span class="vcard">' . get_the_author() . '</span>' ); |
| 110 | } elseif ( is_year() ) { |
| 111 | $title = get_the_date( _x( 'Y', 'yearly archives date format', 'vkExUnit' ) ); |
| 112 | } elseif ( is_month() ) { |
| 113 | $title = get_the_date( _x( 'F Y', 'monthly archives date format', 'vkExUnit' ) ); |
| 114 | } elseif ( is_day() ) { |
| 115 | $title = get_the_date( _x( 'F j, Y', 'daily archives date format', 'vkExUnit' ) ); |
| 116 | } elseif ( is_tax( 'post_format' ) ) { |
| 117 | if ( is_tax( 'post_format', 'post-format-aside' ) ) { |
| 118 | $title = _x( 'Asides', 'post format archive title' ); |
| 119 | } elseif ( is_tax( 'post_format', 'post-format-gallery' ) ) { |
| 120 | $title = _x( 'Galleries', 'post format archive title' ); |
| 121 | } elseif ( is_tax( 'post_format', 'post-format-image' ) ) { |
| 122 | $title = _x( 'Images', 'post format archive title' ); |
| 123 | } elseif ( is_tax( 'post_format', 'post-format-video' ) ) { |
| 124 | $title = _x( 'Videos', 'post format archive title' ); |
| 125 | } elseif ( is_tax( 'post_format', 'post-format-quote' ) ) { |
| 126 | $title = _x( 'Quotes', 'post format archive title' ); |
| 127 | } elseif ( is_tax( 'post_format', 'post-format-link' ) ) { |
| 128 | $title = _x( 'Links', 'post format archive title' ); |
| 129 | } elseif ( is_tax( 'post_format', 'post-format-status' ) ) { |
| 130 | $title = _x( 'Statuses', 'post format archive title' ); |
| 131 | } elseif ( is_tax( 'post_format', 'post-format-audio' ) ) { |
| 132 | $title = _x( 'Audio', 'post format archive title' ); |
| 133 | } elseif ( is_tax( 'post_format', 'post-format-chat' ) ) { |
| 134 | $title = _x( 'Chats', 'post format archive title' ); |
| 135 | } |
| 136 | } elseif ( is_post_type_archive() ) { |
| 137 | $title = post_type_archive_title( '', false ); |
| 138 | } elseif ( is_tax() ) { |
| 139 | $title = single_term_title( '', false ); |
| 140 | } elseif ( is_home() && ! is_front_page() ) { |
| 141 | $vkExUnit_page_for_posts = vkExUnit_get_page_for_posts(); |
| 142 | $title = $vkExUnit_page_for_posts['post_top_name']; |
| 143 | } else { |
| 144 | global $wp_query; |
| 145 | // get post type |
| 146 | $postType = $wp_query->query_vars['post_type']; |
| 147 | if ( $postType ) { |
| 148 | $title = get_post_type_object( $postType )->labels->name; |
| 149 | } else { |
| 150 | $title = __( 'Archives', 'vkExUnit' ); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | return apply_filters( 'vkExUnit_get_the_archive_title', $title ); |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /*-------------------------------------------*/ |
| 159 | /* Page description |
| 160 | /*-------------------------------------------*/ |
| 161 | function vkExUnit_get_pageDescription() { |
| 162 | global $wp_query; |
| 163 | $post = $wp_query->get_queried_object(); |
| 164 | if ( is_front_page() ) { |
| 165 | if ( isset( $post->post_excerpt ) && $post->post_excerpt ) { |
| 166 | $pageDescription = get_the_excerpt(); |
| 167 | } else { |
| 168 | $pageDescription = get_bloginfo( 'description' ); |
| 169 | } |
| 170 | } else if ( is_home() ) { |
| 171 | $page_for_posts = vkExUnit_get_page_for_posts(); |
| 172 | if ( $page_for_posts['post_top_use'] ) { |
| 173 | $page = get_post( $page_for_posts['post_top_id'] ); |
| 174 | $pageDescription = $page->post_excerpt; |
| 175 | } else { |
| 176 | $pageDescription = get_bloginfo( 'description' ); |
| 177 | } |
| 178 | } else if ( is_category() || is_tax() ) { |
| 179 | if ( ! $post->description ) { |
| 180 | $pageDescription = sprintf( __( 'About %s', 'vkExUnit' ),single_cat_title( '',false ) ).' '.get_bloginfo( 'name' ).' '.get_bloginfo( 'description' ); |
| 181 | } else { |
| 182 | $pageDescription = $post->description; |
| 183 | } |
| 184 | } else if ( is_tag() ) { |
| 185 | $pageDescription = strip_tags( tag_description() ); |
| 186 | $pageDescription = str_replace( array( "\r\n", "\r", "\n" ), '', $pageDescription ); // delete br |
| 187 | if ( ! $pageDescription ) { |
| 188 | $pageDescription = sprintf( __( 'About %s', 'vkExUnit' ),single_tag_title( '',false ) ).' '.get_bloginfo( 'name' ).' '.get_bloginfo( 'description' ); |
| 189 | } |
| 190 | } else if ( is_archive() ) { |
| 191 | if ( is_year() ) { |
| 192 | $description_date = get_the_date( _x( 'Y', 'yearly archives date format', 'vkExUnit' ) ); |
| 193 | $pageDescription = sprintf( _x( 'Article of %s.','Yearly archive description', 'vkExUnit' ), $description_date ); |
| 194 | $pageDescription .= ' '.get_bloginfo( 'name' ).' '.get_bloginfo( 'description' ); |
| 195 | } else if ( is_month() ) { |
| 196 | $description_date = get_the_date( _x( 'F Y', 'monthly archives date format', 'vkExUnit' ) ); |
| 197 | $pageDescription = sprintf( _x( 'Article of %s.','Archive description', 'vkExUnit' ),$description_date ); |
| 198 | $pageDescription .= ' '.get_bloginfo( 'name' ).' '.get_bloginfo( 'description' ); |
| 199 | } else if ( is_author() ) { |
| 200 | $userObj = get_queried_object(); |
| 201 | $pageDescription = sprintf( _x( 'Article of %s.','Archive description', 'vkExUnit' ),esc_html( $userObj->display_name ) ); |
| 202 | $pageDescription .= ' '.get_bloginfo( 'name' ).' '.get_bloginfo( 'description' ); |
| 203 | } else { |
| 204 | $postType = get_post_type(); |
| 205 | $pageDescription = sprintf( _x( 'Article of %s.','Archive description', 'vkExUnit' ),esc_html( get_post_type_object( $postType )->labels->name ) ); |
| 206 | $pageDescription .= ' '.get_bloginfo( 'name' ).' '.get_bloginfo( 'description' ); |
| 207 | } |
| 208 | } else if ( is_page() || is_single() ) { |
| 209 | $metaExcerpt = $post->post_excerpt; |
| 210 | if ( $metaExcerpt ) { |
| 211 | $pageDescription = $metaExcerpt; |
| 212 | } else { |
| 213 | $pageDescription = mb_substr( strip_tags( $post->post_content ), 0, 240 ); // kill tags and trim 240 chara |
| 214 | } |
| 215 | } else { |
| 216 | $pageDescription = get_bloginfo( 'description' ); |
| 217 | } |
| 218 | global $paged; |
| 219 | if ( $paged != '0' ) { |
| 220 | $pageDescription = '['.sprintf( __( 'Page of %s', 'vkExUnit' ),$paged ).'] '.$pageDescription; |
| 221 | } |
| 222 | $pageDescription = apply_filters( 'vkExUnit_pageDescriptionCustom', $pageDescription ); |
| 223 | $pageDescription = esc_html( strip_tags( $pageDescription ) ); |
| 224 | // Delete Line break |
| 225 | $pageDescription = str_replace( array( "\r\n", "\r", "\n" ), '', $pageDescription ); |
| 226 | return $pageDescription; |
| 227 | } |
| 228 | |
| 229 | function vkExUnit_is_excerpt() { |
| 230 | global $wp_current_filter; |
| 231 | if ( in_array( 'get_the_excerpt', (array) $wp_current_filter ) ) { return true; } |
| 232 | return false; |
| 233 | } |
| 234 |