MOON
Server: Apache
System: Linux server1.primemusicproductions.com 4.18.0-477.27.2.el8_8.x86_64 #1 SMP Fri Sep 29 08:21:01 EDT 2023 x86_64
User: primrwxj (1001)
PHP: 8.3.3
Disabled: NONE
Upload Files
File: /home/primrwxj/thepassiveincomeideas.com/wp-content/plugins/wpauto-pro/wpauto-init.php
<?php

class WPAuto_Init {

	public static $instance = null;
	
	public static $wpauto_options = null;
		
	public function __construct() {
		
		// Set plugin options
		$wpauto_options = get_option( 'wpauto_options' );
		// set default option values
		if( empty( $wpauto_options ) ) {
			$wpauto_options = $this->set_default_values();
		}
		self::$wpauto_options = !empty( $wpauto_options ) ? $wpauto_options : array();
		
		add_action( 'current_screen', [ $this, 'wpauto_this_screen' ] );
					
		// Create Post Type
		$this->wpauto_post_type();
		
		// Create post options
		$this->wpauto_post_options();
		
		// Cron initiate
		$this->init_cron();		
		
		// SVG class
		$this->wpauto_svg_class();
		
		// Admin menu
		$this->wpauto_admin_menu();
		
		// Database logger
		require_once WPAUTO_DIR . "inc/class.wpauto-db-logger.php";
		
		add_filter( 'plugin_row_meta', [ $this, 'wpauto_add_plugin_row_meta' ], 10, 2 );
		
		// Add global filters for link post redirects (only if enabled)
		$wpauto_options = self::$wpauto_options;
		$enable_link_post_redirect = isset( $wpauto_options['enable_link_post_redirect'] ) && $wpauto_options['enable_link_post_redirect'] ? true : false;
		
		if( $enable_link_post_redirect ) {
			$this->add_link_post_redirect_filters();
		}
		
	}
	
	public function wpauto_add_plugin_row_meta( $links, $file ) {
		
		// Target only your plugin
		if( $file === WPAUTO_BASENAME ) {
			$custom_links = array(
				'<a href="https://aipublish.com/" target="_blank">' . esc_html__('Support', 'wpauto' ) . '</a>'
			);

			// Append custom links to the existing ones
			$links = array_merge($links, $custom_links);
		}
		
		return $links;
		
	}
	
	/**
	 * Add global filters for link post redirects
	 */
	public function add_link_post_redirect_filters() {
		// Add filters and hooks for link post redirects
		add_filter( 'post_link', array( $this, 'redirect_link_posts_to_source' ), 10, 2 );
		add_filter( 'the_permalink', array( $this, 'redirect_link_posts_to_source' ), 10, 2 );
		add_filter( 'the_title', array( $this, 'modify_link_post_title' ), 10, 2 );
		add_filter( 'the_content', array( $this, 'add_link_post_redirect_content' ) );
		add_action( 'wp_head', array( $this, 'add_link_post_redirect_script' ) );
		add_action( 'wp_head', array( $this, 'add_link_post_meta_redirect' ) );
	}
	
	/**
	 * Redirect link posts to source URL
	 */
	public function redirect_link_posts_to_source( $post_link, $post ) {
		// Check if this post has the redirect meta
		$redirect_url = get_post_meta( $post->ID, 'wpauto_source_redirect_url', true );
		
		if( !empty( $redirect_url ) ) {
			return $redirect_url;
		}
		
		return $post_link;
	}
	
	/**
	 * Modify link post title to indicate it's a link
	 */
	public function modify_link_post_title( $title, $post_id = null ) {
		// Only modify on single post pages and if we have a post ID
		if( !is_single() || !$post_id ) {
			return $title;
		}
		
		// Check if this post has the redirect meta
		$redirect_url = get_post_meta( $post_id, 'wpauto_source_redirect_url', true );
		
		if( !empty( $redirect_url ) ) {
			// Add a small icon or indicator that this is a link post
			$title .= ' <span style="color: #0073aa; font-size: 0.8em;">🔗</span>';
		}
		
		return $title;
	}
	
	/**
	 * Add redirect content for link posts
	 */
	public function add_link_post_redirect_content( $content ) {
		// Only modify on single post pages
		if( !is_single() ) {
			return $content;
		}
		
		global $post;
		if( !$post ) {
			return $content;
		}
		
		// Check if this post has the redirect meta
		$redirect_url = get_post_meta( $post->ID, 'wpauto_source_redirect_url', true );
		
		if( !empty( $redirect_url ) ) {
			// Add a prominent redirect button/link
			$redirect_content = '<div style="text-align: center; margin: 20px 0; padding: 20px; background: #f9f9f9; border: 1px solid #ddd; border-radius: 5px;">';
			$redirect_content .= '<p style="margin: 0 0 15px 0; font-size: 16px;"><strong>This is a link post. Click below to visit the source:</strong></p>';
			$redirect_content .= '<a href="' . esc_url( $redirect_url ) . '" target="_blank" style="display: inline-block; padding: 12px 24px; background: #0073aa; color: white; text-decoration: none; border-radius: 3px; font-weight: bold;">Visit Source Article</a>';
			$redirect_content .= '</div>';
			
			$content = $redirect_content . $content;
		}
		
		return $content;
	}
	
	/**
	 * Add JavaScript for link post redirects
	 */
	public function add_link_post_redirect_script() {
		// Only add script on single post pages
		if( !is_single() ) {
			return;
		}
		
		global $post;
		if( !$post ) {
			return;
		}
		
		// Check if this post has the redirect meta
		$redirect_url = get_post_meta( $post->ID, 'wpauto_source_redirect_url', true );
		
		if( !empty( $redirect_url ) ) {
			?>
			<script type="text/javascript">
			jQuery(document).ready(function($) {
				// Redirect when clicking on the post title
				$('.entry-title a, h1.entry-title a, .post-title a, h1 a, .title a').click(function(e) {
					e.preventDefault();
					window.open('<?php echo esc_url( $redirect_url ); ?>', '_blank');
				});
				
				// Also redirect when clicking on the post title without link (if theme doesn't wrap title in link)
				$('.entry-title, h1.entry-title, .post-title, h1:first').click(function(e) {
					if( !$(this).find('a').length ) {
						e.preventDefault();
						window.open('<?php echo esc_url( $redirect_url ); ?>', '_blank');
					}
				});
			});
			</script>
			<?php
		}
	}
	
	/**
	 * Add meta redirect for link posts (fallback)
	 */
	public function add_link_post_meta_redirect() {
		// Only add on single post pages
		if( !is_single() ) {
			return;
		}
		
		global $post;
		if( !$post ) {
			return;
		}
		
		// Check if this post has the redirect meta
		$redirect_url = get_post_meta( $post->ID, 'wpauto_source_redirect_url', true );
		
		if( !empty( $redirect_url ) ) {
			// Add a meta tag that indicates this is a link post
			echo '<meta name="wpauto-link-post" content="' . esc_attr( $redirect_url ) . '">' . "\n";
		}
	}
	
	public function init_cron() {
		$license_stat = $this->get_license_data();
		if( $license_stat ) {
			$wpauto_options = self::$wpauto_options;
			// Only initialize cron if it's NOT paused (cron_pause should be 0 or not set)
			if( !isset( $wpauto_options['cron_pause'] ) || !$wpauto_options['cron_pause'] ) {
				require_once WPAUTO_DIR . "inc/class.wp-schedule.php";
			}
		}		
	}
	
	public function wpauto_this_screen() {
		$current_screen = get_current_screen();

		if( $current_screen->id === "edit-wpauto" ) {
			//add_filter( 'get_edit_post_link', [ $this, 'wpauto_edit_post_link' ], 10, 3 );
		}
	}
	
	public function wpauto_edit_post_link( $link, $post_id, $context ) {
		return admin_url( 'admin.php?page=wpauto_campaign&wpauto_id='. $post_id );
	}
	
	public function wpauto_post_type() {
		require_once WPAUTO_DIR . "admin/class.wpauto-post.php";
	}
	
	public function wpauto_post_options() {
		//require_once WPAUTO_DIR . "admin/meta-box/class.meta-box.php";
	}
	
	public function wpauto_admin_menu() {
		require_once WPAUTO_DIR . "admin/class.admin-menu.php";
	}
	
	public function wpauto_svg_class() {
		require_once WPAUTO_DIR . "admin/class.wpauto-svg.php";
	}
	
	public function set_default_values() {
		
		$options = '{"openai_api":"","pixabay_api":"","pexels_api":"","ls_email":"","ls_api":"","amazon_aff_id":"","cron_pause":"0"}';
		update_option( 'wpauto_options', json_decode( $options, true ) );
		
		return $options;
		
	}
	
	public function get_license_data() {
		
		return get_option( 'wpauto_pro_thlmdata' );
		
	}
	
	public static function instance() {
		if ( is_null( self::$instance ) ) {
			self::$instance = new self();
		}
		return self::$instance;
	}
	
} WPAuto_Init::instance();

function wpauto_camp_cur_running_stat() {	
	return get_option( 'wpauto_cur_running_stat' );	
}