PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Quản lý website xem phim online PHP/thudang/public_html/mnet/wp-content/plugins/wordpress-seo/frontend/class-breadcrumbs.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 327 lines | 284 code | 33 blank | 10 comment | 133 complexity | 51e98533a3ee5bd0ff7de774268798e7 MD5 | raw file
  1. <?php
  2. class WPSEO_Breadcrumbs {
  3. function __construct() {
  4. $options = get_option("wpseo_internallinks");
  5. if (isset($options['trytheme']) && $options['trytheme']) {
  6. // Thesis
  7. add_action('thesis_hook_before_headline', array(&$this, 'breadcrumb_output'),10,1);
  8. // Hybrid
  9. remove_action( 'hybrid_before_content', 'hybrid_breadcrumb' );
  10. add_action( 'hybrid_before_content', array(&$this, 'breadcrumb_output'), 10, 1 );
  11. // Thematic
  12. add_action('thematic_belowheader', array(&$this, 'breadcrumb_output'),10,1);
  13. add_action('framework_hook_content_open', array(&$this, 'breadcrumb_output'),10,1);
  14. }
  15. // If breadcrumbs are active (which they are otherwise this class wouldn't be instantiated), there's no reason
  16. // to have bbPress breadcrumbs as well.
  17. add_filter( 'bbp_get_breadcrumb', '__return_false' );
  18. }
  19. function breadcrumb_output() {
  20. $this->breadcrumb('<div id="wpseobreadcrumb">','</div>');
  21. return;
  22. }
  23. function bold_or_not($input) {
  24. $opt = get_option("wpseo_internallinks");
  25. if ( isset($opt['breadcrumbs-boldlast']) && $opt['breadcrumbs-boldlast'] ) {
  26. return '<strong>'.$input.'</strong>';
  27. } else {
  28. return $input;
  29. }
  30. }
  31. function get_bc_title( $id_or_name, $type = 'post_type' ) {
  32. $bctitle = wpseo_get_value( 'bctitle', $id_or_name );
  33. $bctitle = ( !empty($bctitle) ) ? $bctitle : strip_tags( get_the_title( $id_or_name ) );
  34. return apply_filters( 'wp_seo_get_bc_title', $bctitle, $id_or_name, $type );
  35. }
  36. function get_term_parents($term, $taxonomy) {
  37. $origterm = $term;
  38. $parents = array();
  39. while ($term->parent != 0) {
  40. $term = get_term($term->parent, $taxonomy);
  41. if ($term != $origterm)
  42. $parents[] = $term;
  43. }
  44. return $parents;
  45. }
  46. function get_menu_trail($menu = '', $parent = false, $trail = array()) {
  47. global $post, $wpdb;
  48. // No parent is set so we start by getting the parent of the current post
  49. if ( !$parent ) {
  50. $query = "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='_menu_item_menu_item_parent' AND post_id = (SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_menu_item_object_id' AND meta_value=$post->ID)";
  51. $result = $wpdb->get_results( $query );
  52. if( count($result) > 0 ) {
  53. $parent = $result[0]->meta_value;
  54. }
  55. // A parent is set and we want to get the grandparent.
  56. } else {
  57. $query = "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='_menu_item_menu_item_parent' AND post_id = $parent";
  58. $result = $wpdb->get_results( $query );
  59. if( count($result) > 0 ) {
  60. $parent = $result[0]->meta_value;
  61. } else {
  62. $parent = 0;
  63. }
  64. }
  65. // The parent is the root of the menu let's return the trail
  66. if ( $parent == 0) {
  67. return $trail;
  68. // There still are grandparents to discover
  69. } else {
  70. $trail[] = $parent;
  71. $temptrail = $this->get_menu_trail('', $parent, $trail);
  72. return $temptrail;
  73. }
  74. }
  75. function in_menu( $selectedmenu ) {
  76. global $wpdb, $post;
  77. $query = "SELECT * FROM $wpdb->term_relationships WHERE term_taxonomy_id = $selectedmenu AND object_id IN (SELECT post_id FROM $wpdb->postmeta WHERE meta_key='_menu_item_object_id' AND meta_value=$post->ID)";
  78. $result = $wpdb->get_results( $query );
  79. if( count($result) > 0 ) {
  80. return true;
  81. } else {
  82. return false;
  83. }
  84. }
  85. function get_post_for_menunode( $node_id ) {
  86. global $wpdb;
  87. $query = "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key='_menu_item_object_id' AND post_id = $node_id";
  88. $result = $wpdb->get_results( $query );
  89. if( count($result) > 0 ) {
  90. return $result[0]->meta_value;
  91. } else {
  92. return 0;
  93. }
  94. }
  95. function breadcrumb($prefix = '', $suffix = '', $display = true) {
  96. $options = get_wpseo_options();
  97. global $wp_query, $post, $paged;
  98. $opt = get_option("wpseo_internallinks");
  99. $on_front = get_option('show_on_front');
  100. $blog_page = get_option('page_for_posts');
  101. $sep = ( isset($opt['breadcrumbs-sep']) && $opt['breadcrumbs-sep'] != '' ) ? $opt['breadcrumbs-sep'] : '&raquo;';
  102. $home = ( isset($opt['breadcrumbs-home']) && $opt['breadcrumbs-home'] != '' ) ? $opt['breadcrumbs-home'] : __('Home','wordpress-seo');
  103. $selmenu = ( isset($opt['breadcrumbs-selectedmenu']) && $opt['breadcrumbs-selectedmenu'] != '' ) ? $opt['breadcrumbs-selectedmenu'] : 0;
  104. if ( "page" == $on_front && 'post' == get_post_type() ) {
  105. $homelink = '<a href="'.get_permalink(get_option('page_on_front')).'">'.$home.'</a>';
  106. $bloglink = $homelink;
  107. if ( $blog_page && ( !isset($opt['breadcrumbs-blog-remove']) || !$opt['breadcrumbs-blog-remove'] ) )
  108. $bloglink = $homelink.' '.$sep.' <a href="'.get_permalink($blog_page).'">'.$this->get_bc_title($blog_page).'</a>';
  109. } else {
  110. $homelink = '<a href="'.get_bloginfo('url').'">'.$home.'</a>';
  111. $bloglink = $homelink;
  112. }
  113. if ( ( $on_front == "page" && is_front_page() ) || ( $on_front == "posts" && is_home() ) ) {
  114. $output = $this->bold_or_not($home);
  115. } else if ( $on_front == "page" && is_home() ) {
  116. $output = $homelink.' '.$sep.' '.$this->bold_or_not( $this->get_bc_title($blog_page) );
  117. } else if ( is_singular() ) {
  118. $output = $bloglink.' '.$sep.' ';
  119. if( isset($opt['breadcrumbs-menus']) && $opt['breadcrumbs-menus'] = 'on'){
  120. $use_menu = $this->in_menu( $selmenu );
  121. }
  122. if ( function_exists('bbp_body_class') && count( bbp_body_class( array() ) ) > 1 ) {
  123. remove_filter('bbp_get_breadcrumb','__return_false');
  124. $output .= bbp_get_breadcrumb( ' '.$sep.' ' );
  125. add_filter('bbp_get_breadcrumb','__return_false');
  126. } else if( isset( $use_menu ) && $use_menu ){
  127. $trail = $this->get_menu_trail();
  128. $trail = array_reverse ( $trail );
  129. $trailposts = array();
  130. for($t = 0; $t < count($trail); $t++){
  131. $trailposts[] = $this->get_post_for_menunode($trail[$t]);
  132. }
  133. for($t = 0; $t < count($trail); $t++){
  134. $bctitle = ( get_the_title( $trail[$t] ) == '' ) ? get_the_title( $trailposts[$t] ) : get_the_title( $trail[$t] );
  135. $output .= '<a href="' . get_permalink( $trailposts[$t] ) . '">' . $bctitle .'</a> ' . $sep . ' ';
  136. }
  137. $output .= $this->bold_or_not( $this->get_bc_title( $post->ID ) );
  138. } else {
  139. $post_type = get_post_type();
  140. if ( function_exists('get_post_type_archive_link') && get_post_type_archive_link( $post_type ) ) {
  141. if ( isset($options['bctitle-ptarchive-'.$post_type]) && '' != $options['bctitle-ptarchive-'.$post_type] ) {
  142. $archive_title = $options['bctitle-ptarchive-'.$post_type];
  143. } else {
  144. $post_type_obj = get_post_type_object( $post_type );
  145. $archive_title = $post_type_obj->labels->menu_name;
  146. }
  147. $output .= '<a href="'.get_post_type_archive_link( $post_type ).'">'.$archive_title.'</a> ' . $sep . ' ';
  148. }
  149. if ( 0 == $post->post_parent ) {
  150. if ( isset( $opt['post_types-'.$post->post_type.'-maintax'] ) && $opt['post_types-'.$post->post_type.'-maintax'] != '0' ) {
  151. $main_tax = $opt['post_types-'.$post->post_type.'-maintax'];
  152. $terms = wp_get_object_terms( $post->ID, $main_tax );
  153. if ( is_taxonomy_hierarchical($main_tax) && $terms[0]->parent != 0 ) {
  154. $parents = $this->get_term_parents($terms[0], $main_tax);
  155. $parents = array_reverse($parents);
  156. foreach($parents as $parent) {
  157. $bctitle = wpseo_get_term_meta( $parent, $main_tax, 'bctitle' );
  158. if (!$bctitle)
  159. $bctitle = $parent->name;
  160. $output .= '<a href="'.get_term_link( $parent, $main_tax ).'">'.$bctitle.'</a> '.$sep.' ';
  161. }
  162. }
  163. if ( count($terms) > 0 ) {
  164. $bctitle = wpseo_get_term_meta( $terms[0], $main_tax, 'bctitle' );
  165. if (!$bctitle)
  166. $bctitle = $terms[0]->name;
  167. $output .= '<a href="'.get_term_link($terms[0], $main_tax).'">'.$bctitle.'</a> '.$sep.' ';
  168. }
  169. }
  170. $output .= $this->bold_or_not( $this->get_bc_title( $post->ID ) );
  171. } else {
  172. if (isset($post->ancestors)) {
  173. if (is_array($post->ancestors))
  174. $ancestors = array_values($post->ancestors);
  175. else
  176. $ancestors = array($post->ancestors);
  177. } else {
  178. $ancestors = array($post->post_parent);
  179. }
  180. // Reverse the order so it's oldest to newest
  181. $ancestors = array_reverse( apply_filters( 'wp_seo_get_bc_ancestors', $ancestors ) );
  182. foreach ( $ancestors as $ancestor ) {
  183. $output .= '<a href="'.get_permalink($ancestor).'">'.$this->get_bc_title( $ancestor ).'</a> '.$sep.' ';
  184. }
  185. $output .= $this->bold_or_not( $this->get_bc_title( $post->ID ) );
  186. }
  187. }
  188. } else {
  189. if (! is_404() ) {
  190. $output = $bloglink.' '.$sep.' ';
  191. } else {
  192. $output = $homelink.' '.$sep.' ';
  193. }
  194. if ( function_exists('is_post_type_archive') && is_post_type_archive() ) {
  195. $post_type = get_post_type();
  196. if ( isset($options['bctitle-ptarchive-'.$post_type]) && '' != $options['bctitle-ptarchive-'.$post_type] ) {
  197. $archive_title = $options['bctitle-ptarchive-'.$post_type];
  198. } else {
  199. $post_type_obj = get_post_type_object( $post_type );
  200. $archive_title = $post_type_obj->labels->menu_name;
  201. }
  202. $output .= $this->bold_or_not( $archive_title );
  203. } else if ( is_tax() || is_tag() || is_category() ) {
  204. $term = $wp_query->get_queried_object();
  205. if ( isset($options['taxonomy-'.$term->taxonomy.'-ptparent']) && $options['taxonomy-'.$term->taxonomy.'-ptparent'] != '' ) {
  206. $post_type = $options['taxonomy-'.$term->taxonomy.'-ptparent'];
  207. if ( 'post' == $post_type && get_option('show_on_front') == 'page' ) {
  208. $posts_page = get_option('page_for_posts');
  209. if ( $posts_page ) {
  210. $output .= '<a href="'.get_permalink( $posts_page ).'">'.$this->get_bc_title( $posts_page ).'</a> '.$sep.' ';
  211. }
  212. } else {
  213. if ( isset($options['bctitle-ptarchive-'.$post_type]) && '' != $options['bctitle-ptarchive-'.$post_type] ) {
  214. $archive_title = $options['bctitle-ptarchive-'.$post_type];
  215. } else {
  216. $post_type_obj = get_post_type_object( $post_type );
  217. $archive_title = $post_type_obj->labels->menu_name;
  218. }
  219. $output .= '<a href="'.get_post_type_archive_link( $post_type ).'">'.$archive_title.'</a> '.$sep.' ';
  220. }
  221. }
  222. if ( is_taxonomy_hierarchical($term->taxonomy) && $term->parent != 0 ) {
  223. $parents = $this->get_term_parents($term, $term->taxonomy);
  224. $parents = array_reverse( $parents );
  225. foreach($parents as $parent) {
  226. $bctitle = wpseo_get_term_meta( $parent, $term->taxonomy, 'bctitle' );
  227. if (!$bctitle)
  228. $bctitle = $parent->name;
  229. $output .= '<a href="'.get_term_link( $parent, $term->taxonomy ).'">'.$bctitle.'</a> '.$sep.' ';
  230. }
  231. }
  232. $bctitle = wpseo_get_term_meta( $term, $term->taxonomy, 'bctitle' );
  233. if (!$bctitle)
  234. $bctitle = $term->name;
  235. if ($paged)
  236. $output .= $this->bold_or_not('<a href="'.get_term_link( $term, $term->taxonomy ).'">'.$bctitle.'</a>');
  237. else
  238. $output .= $this->bold_or_not($bctitle);
  239. } else if ( is_date() ) {
  240. if ( isset($opt['breadcrumbs-archiveprefix']) )
  241. $bc = $opt['breadcrumbs-archiveprefix'];
  242. else
  243. $bc = __('Archives for','wordpress-seo');
  244. if ( is_day() ) {
  245. global $wp_locale;
  246. $output .= '<a href="'.get_month_link( get_query_var('year'), get_query_var('monthnum') ).'">'.$wp_locale->get_month( get_query_var('monthnum') ).' '.get_query_var('year').'</a> '.$sep.' ';
  247. $output .= $this->bold_or_not( $bc." ".get_the_date() );
  248. } else if ( is_month() ) {
  249. $output .= $this->bold_or_not( $bc." ".single_month_title(' ',false) );
  250. } else if ( is_year() ) {
  251. $output .= $this->bold_or_not( $bc." ".get_query_var('year') );
  252. }
  253. } elseif ( is_author() ) {
  254. if ( isset($opt['breadcrumbs-archiveprefix']) )
  255. $bc = $opt['breadcrumbs-archiveprefix'];
  256. else
  257. $bc = __('Archives for','wordpress-seo');
  258. $user = $wp_query->get_queried_object();
  259. $output .= $this->bold_or_not($bc." ".$user->display_name);
  260. } elseif ( is_search() ) {
  261. if ( isset($opt['breadcrumbs-searchprefix']) && $opt['breadcrumbs-searchprefix'] != '' )
  262. $bc = $opt['breadcrumbs-searchprefix'];
  263. else
  264. $bc = __('You searched for','wordpress-seo');
  265. $output .= $this->bold_or_not($bc.' "'.stripslashes(strip_tags(get_search_query())).'"');
  266. } elseif ( isset( $wp_query->query_vars['bbp_topic_tag'] ) ) {
  267. remove_filter('bbp_get_breadcrumb','__return_false');
  268. $output .= bbp_get_breadcrumb( ' '.$sep.' ' );
  269. add_filter('bbp_get_breadcrumb','__return_false');
  270. } elseif ( is_404() ) {
  271. if ( isset($opt['breadcrumbs-404crumb']) && $opt['breadcrumbs-404crumb'] != '' )
  272. $crumb404 = $opt['breadcrumbs-404crumb'];
  273. else
  274. $crumb404 = __('Error 404: Page not found','wordpress-seo');
  275. $output .= $this->bold_or_not($crumb404);
  276. }
  277. }
  278. if ( isset($opt['breadcrumbs-prefix']) && $opt['breadcrumbs-prefix'] != "" ) {
  279. $output = $opt['breadcrumbs-prefix']." ".$output;
  280. }
  281. if ($display) {
  282. echo $prefix.$output.$suffix;
  283. return true;
  284. } else {
  285. return $prefix.$output.$suffix;
  286. }
  287. }
  288. }
  289. if (!function_exists('yoast_breadcrumb')) {
  290. function yoast_breadcrumb($prefix = '', $suffix = '', $display = true) {
  291. $wpseo_bc = new WPSEO_Breadcrumbs();
  292. return $wpseo_bc->breadcrumb($prefix, $suffix, $display);
  293. }
  294. }