Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/accelera.../classes
File: class-ampforwp-infinite-scroll.php
<?php
[0] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[1] Fix | Delete
exit;
[2] Fix | Delete
}
[3] Fix | Delete
/**
[4] Fix | Delete
* Class: To enable Infinite Scroll in AMP
[5] Fix | Delete
* Note: For performance reasons the component will render a maximum of three documents (total) on screen at one time. This limit may be changed or removed in the future.
[6] Fix | Delete
* Read more about it here: https://www.ampproject.org/docs/reference/components/amp-next-page
[7] Fix | Delete
*/
[8] Fix | Delete
if( ! class_exists('AMPforWP_Infinite_Scroll') ) {
[9] Fix | Delete
[10] Fix | Delete
class AMPforWP_Infinite_Scroll
[11] Fix | Delete
{
[12] Fix | Delete
private $paged;
[13] Fix | Delete
private $is_single = false;
[14] Fix | Delete
private $is_loop = false;
[15] Fix | Delete
function __construct()
[16] Fix | Delete
{
[17] Fix | Delete
$this->is_single = true == $this->is_single() ? $this->is_single() : $this->is_single;
[18] Fix | Delete
$this->is_loop = true == $this->is_loop() ? $this->is_loop() : $this->is_loop;
[19] Fix | Delete
$this->paged = $this->paged();
[20] Fix | Delete
if ( $this->is_single && 'page' != get_post_type(ampforwp_get_the_ID()) ){
[21] Fix | Delete
// amp-next-page experiment meta tag
[22] Fix | Delete
add_action('amp_experiment_meta', array( $this, 'amp_experiment_meta') );
[23] Fix | Delete
// amp-next-page script
[24] Fix | Delete
add_filter('ampforwp_post_template_data', array( $this , 'amp_infinite_scroll_script') );
[25] Fix | Delete
// amp-next-page tag
[26] Fix | Delete
if ( 4 != ampforwp_get_setting('amp-design-selector') || (class_exists('AmpforwpAmpLayouts')) && 3 == ampforwp_get_setting('single-design-type') )
[27] Fix | Delete
add_action('ampforwp_above_related_post', array( $this , 'amp_next_page') );
[28] Fix | Delete
else {
[29] Fix | Delete
if (true == ampforwp_get_setting('ampforwp-infinite-scroll-new-features')) {
[30] Fix | Delete
add_action('ampforwp_global_after_footer', array( $this , 'amp_next_page') );
[31] Fix | Delete
}else{
[32] Fix | Delete
add_action('ampforwp_single_design_type_handle', array( $this , 'amp_next_page') );
[33] Fix | Delete
}
[34] Fix | Delete
}
[35] Fix | Delete
}
[36] Fix | Delete
if ( $this->is_loop ) {
[37] Fix | Delete
// amp-next-page experiment meta tag
[38] Fix | Delete
add_action('amp_experiment_meta', array( $this, 'amp_experiment_meta') );
[39] Fix | Delete
// amp-next-page script
[40] Fix | Delete
add_filter('ampforwp_post_template_data', array( $this , 'amp_infinite_scroll_script') );
[41] Fix | Delete
// amp-next-page tag
[42] Fix | Delete
add_action('ampforwp_loop_before_pagination', array( $this , 'amp_next_page') );
[43] Fix | Delete
// Next Posts Link
[44] Fix | Delete
add_filter('ampforwp_next_posts_link', array( $this , 'next_posts_link') , 10 , 2 );
[45] Fix | Delete
}
[46] Fix | Delete
}
[47] Fix | Delete
public function is_single() {
[48] Fix | Delete
if ( is_single() && true == ampforwp_get_setting('ampforwp-infinite-scroll-single') ) {
[49] Fix | Delete
return true;
[50] Fix | Delete
}
[51] Fix | Delete
return false;
[52] Fix | Delete
}
[53] Fix | Delete
public function is_loop() {
[54] Fix | Delete
$script = true;
[55] Fix | Delete
if ( (ampforwp_is_home() || is_archive()) && (true == ampforwp_get_setting('ampforwp-infinite-scroll-home') || true == ampforwp_get_setting('ampforwp-wcp-infinite-scroll') ) ) {
[56] Fix | Delete
if( function_exists('is_product_category') && is_product_category() || function_exists('is_product_tag') && is_product_tag() || function_exists('is_shop') && is_shop()){
[57] Fix | Delete
$script = false;
[58] Fix | Delete
}
[59] Fix | Delete
$script = apply_filters('ampforwp_modify_infinite_scroll_script', $script);
[60] Fix | Delete
return $script;
[61] Fix | Delete
}
[62] Fix | Delete
return false;
[63] Fix | Delete
}
[64] Fix | Delete
public function paged() {
[65] Fix | Delete
$paged = get_query_var( 'paged' );
[66] Fix | Delete
$page = get_query_var( 'page' );
[67] Fix | Delete
if ( $paged ) {
[68] Fix | Delete
return intval($paged);
[69] Fix | Delete
} elseif ( $page ) {
[70] Fix | Delete
return intval($page);
[71] Fix | Delete
} else {
[72] Fix | Delete
return 1;
[73] Fix | Delete
}
[74] Fix | Delete
}
[75] Fix | Delete
public function amp_experiment_meta() {
[76] Fix | Delete
echo '<meta name="amp-experiments-opt-in" content="amp-next-page">';
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
public function amp_infinite_scroll_script( $data ) {
[80] Fix | Delete
if ( empty( $data['amp_component_scripts']['amp-next-page'] ) ) {
[81] Fix | Delete
if (true == ampforwp_get_setting('ampforwp-infinite-scroll-new-features')) {
[82] Fix | Delete
$data['amp_component_scripts']['amp-next-page'] = 'https://cdn.ampproject.org/v0/amp-next-page-latest.js';
[83] Fix | Delete
}else{
[84] Fix | Delete
$data['amp_component_scripts']['amp-next-page'] = 'https://cdn.ampproject.org/v0/amp-next-page-0.1.js';
[85] Fix | Delete
}
[86] Fix | Delete
}
[87] Fix | Delete
return $data;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
public function amp_next_page() {
[91] Fix | Delete
$loop_link = $first_url = $first_title = $first_image = $second_url = $second_image = $second_title ='';
[92] Fix | Delete
$single_links = $single_titles = $single_images = $classes = $pages = array();
[93] Fix | Delete
if ( $this->is_loop ) {
[94] Fix | Delete
$loop_link = $this->loop_link();
[95] Fix | Delete
$loop_link1 = $loop_link2 = '';
[96] Fix | Delete
$loop_link1 = $loop_link.($this->paged+1);
[97] Fix | Delete
$loop_link2 = $loop_link.($this->paged+2);
[98] Fix | Delete
if ( true == ampforwp_get_setting('amp-core-end-point') ) {
[99] Fix | Delete
$loop_link1 = ampforwp_url_controller($loop_link1);
[100] Fix | Delete
$loop_link2 = ampforwp_url_controller($loop_link2);
[101] Fix | Delete
}
[102] Fix | Delete
if (true == ampforwp_get_setting('ampforwp-infinite-scroll-new-features')) {
[103] Fix | Delete
$pages[] = array('title'=>'','image'=>'','url'=>$loop_link1);
[104] Fix | Delete
}else{
[105] Fix | Delete
$pages[] = array('title'=>'','image'=>'','ampUrl'=>$loop_link1);
[106] Fix | Delete
$pages[] = array('title'=>'','image'=>'','ampUrl'=>$loop_link2);
[107] Fix | Delete
}
[108] Fix | Delete
}
[109] Fix | Delete
if ( $this->is_single ) {
[110] Fix | Delete
$pages = $this->single_post();
[111] Fix | Delete
}
[112] Fix | Delete
$classes = $this->hide();
[113] Fix | Delete
?>
[114] Fix | Delete
<amp-next-page>
[115] Fix | Delete
<script type="application/json">
[116] Fix | Delete
<?php
[117] Fix | Delete
if (true == ampforwp_get_setting('ampforwp-infinite-scroll-new-features')) {
[118] Fix | Delete
echo wp_json_encode($pages);
[119] Fix | Delete
}else{
[120] Fix | Delete
?>
[121] Fix | Delete
{
[122] Fix | Delete
"pages": <?php echo wp_json_encode($pages);?>,
[123] Fix | Delete
"hideSelectors": <?php echo ampforwp_css_sanitizer($classes);?>
[124] Fix | Delete
}
[125] Fix | Delete
<?php } ?>
[126] Fix | Delete
</script>
[127] Fix | Delete
</amp-next-page>
[128] Fix | Delete
<?php }
[129] Fix | Delete
public function single_post() {
[130] Fix | Delete
global $post;
[131] Fix | Delete
$pages = array();
[132] Fix | Delete
$exclude_ids = ampforwp_exclude_posts();
[133] Fix | Delete
$exclude_ids[] = $post->ID;
[134] Fix | Delete
$query_args = array(
[135] Fix | Delete
'post_type' => get_post_type(),
[136] Fix | Delete
'orderby' => 'date',
[137] Fix | Delete
'ignore_sticky_posts' => 1,
[138] Fix | Delete
'paged' => esc_attr($this->paged),
[139] Fix | Delete
'post__not_in' => $exclude_ids,
[140] Fix | Delete
'has_password' => false ,
[141] Fix | Delete
'post_status'=> 'publish',
[142] Fix | Delete
'posts_per_page' => 2,
[143] Fix | Delete
'no_found_rows' => true
[144] Fix | Delete
);
[145] Fix | Delete
if (ampforwp_get_setting('ampforwp-infinite-scroll-single') && ampforwp_get_setting('ampforwp-infinite-scroll-single-category')){
[146] Fix | Delete
$categories = get_the_category($post->ID);
[147] Fix | Delete
$category_ids = array();
[148] Fix | Delete
if ($categories) {
[149] Fix | Delete
foreach($categories as $individual_category){
[150] Fix | Delete
$category_ids[] = $individual_category->cat_ID;
[151] Fix | Delete
}
[152] Fix | Delete
if(class_exists( 'WPSEO_Options' )){
[153] Fix | Delete
$primary_cat = get_post_meta(ampforwp_get_the_ID(), '_yoast_wpseo_primary_category', true);
[154] Fix | Delete
if (isset($primary_cat)) {
[155] Fix | Delete
$primary_cat = explode( " ", $primary_cat);
[156] Fix | Delete
$category_ids = array_intersect($category_ids,
[157] Fix | Delete
$primary_cat);
[158] Fix | Delete
}
[159] Fix | Delete
}
[160] Fix | Delete
}
[161] Fix | Delete
$query_args['category__in'] = $category_ids;
[162] Fix | Delete
}
[163] Fix | Delete
if (ampforwp_get_setting('ampforwp-infinite-scroll-single') && ampforwp_get_setting('ampforwp-infinite-scroll-single-tag')){
[164] Fix | Delete
$tags = get_the_tags(ampforwp_get_the_ID());
[165] Fix | Delete
if ($tags) {
[166] Fix | Delete
$tags_ids = array();
[167] Fix | Delete
foreach($tags as $individual_tag){
[168] Fix | Delete
$tags_ids[] = $individual_tag->term_id;
[169] Fix | Delete
}
[170] Fix | Delete
}
[171] Fix | Delete
$query_args['tag__in'] = $tags_ids;
[172] Fix | Delete
}
[173] Fix | Delete
$query_args = apply_filters('ampforwp_infinite_scroll_query_args', $query_args);
[174] Fix | Delete
$query = new WP_Query( $query_args );
[175] Fix | Delete
while ($query->have_posts()) {
[176] Fix | Delete
$query->the_post();
[177] Fix | Delete
if (true == ampforwp_get_setting('ampforwp-infinite-scroll-new-features')) {
[178] Fix | Delete
$pages[] = array('title'=>get_the_title(),'image'=>ampforwp_get_post_thumbnail('url', 'full'),'url'=>ampforwp_url_controller( get_permalink() ));
[179] Fix | Delete
}else{
[180] Fix | Delete
$pages[] = array('title'=>get_the_title(),'image'=>ampforwp_get_post_thumbnail('url', 'full'),'ampUrl'=>ampforwp_url_controller( get_permalink() ));
[181] Fix | Delete
}
[182] Fix | Delete
}
[183] Fix | Delete
wp_reset_postdata();
[184] Fix | Delete
return $pages;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
public function loop_link() {
[188] Fix | Delete
global $wp;
[189] Fix | Delete
$amp_url = trailingslashit(home_url($wp->request));
[190] Fix | Delete
if( $this->paged < 2 ) {
[191] Fix | Delete
$amp_url = trailingslashit($amp_url.'page');
[192] Fix | Delete
}
[193] Fix | Delete
else
[194] Fix | Delete
$amp_url = str_replace('/'.$this->paged, '', $amp_url);
[195] Fix | Delete
return $amp_url;
[196] Fix | Delete
}
[197] Fix | Delete
public function hide() {
[198] Fix | Delete
$classes = array();
[199] Fix | Delete
$design = ampforwp_get_setting('amp-design-selector');
[200] Fix | Delete
if ( 1 == $design ) {
[201] Fix | Delete
$classes = array("#pagination",".related_posts", ".amp-wp-footer",".amp-wp-header",".f-w");
[202] Fix | Delete
}
[203] Fix | Delete
if ( 2 == $design ) {
[204] Fix | Delete
$classes = array("#headerwrap","#pagination","#footer",".nav_container",".related_posts",".f-w");
[205] Fix | Delete
}
[206] Fix | Delete
if ( 3 == $design ) {
[207] Fix | Delete
$classes = array("#headerwrap",".relatedpost",".footer_wrapper",".pagination-holder",".f-w");
[208] Fix | Delete
}
[209] Fix | Delete
if ( 4 == $design ) {
[210] Fix | Delete
$classes = array(".p-m-fl",".loop-pagination",".footer",".r-pf",".srp ul",".srp h3","#pagination",".h_m_w", ".f-w");
[211] Fix | Delete
}
[212] Fix | Delete
$classes = (array) apply_filters('ampforwp_infinite_scroll_exclude_items', $classes);
[213] Fix | Delete
return wp_json_encode($classes);
[214] Fix | Delete
}
[215] Fix | Delete
public function next_posts_link( $next_link , $paged ) {
[216] Fix | Delete
// Change the next link to paged+3
[217] Fix | Delete
// reason: amp-next-page will show the results for 3 pages
[218] Fix | Delete
$next_link = preg_replace('/'.($paged+1).'/', ($paged+3), $next_link);
[219] Fix | Delete
//Pagination + infinite scroll creates 404 links #5167
[220] Fix | Delete
preg_match_all('/<a href="(.*?)"(.*?)<\/a>/', $next_link, $match);
[221] Fix | Delete
$url = $match[1][0];
[222] Fix | Delete
$headers = get_headers($url, 1);
[223] Fix | Delete
if(isset($headers[0]) && !stripos($headers[0], "200 OK")){
[224] Fix | Delete
return;
[225] Fix | Delete
}
[226] Fix | Delete
return $next_link;
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
// Initiate the Class
[230] Fix | Delete
new AMPforWP_Infinite_Scroll();
[231] Fix | Delete
}
[232] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function