<?php
/**
 * Twitter Class
 *
 * @package     WP Content Pilot Pro
 * @subpackage  Feed
 * @copyright   Copyright (c) 2019, MD Sultan Nasir Uddin(manikdrmc@gmail.com)
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       1.1.0
 */

defined( 'ABSPATH' ) || exit();

class WPCP_Twitter extends WPCP_Module {
	/**
	 * The single instance of the class
	 *
	 * @var $this ;
	 */
	protected static $_instance = null;

	/**
	 * WPCP_Amazon constructor.
	 */
	public function __construct() {
		add_action( 'wpcp_twitter_campaign_options_meta_fields', 'wpcp_keyword_suggestion_field' );
		add_action( 'wpcp_twitter_campaign_options_meta_fields', 'wpcp_keyword_field' );
		add_action( 'wpcp_twitter_after_post_publish', array( $this, 'maybe_set_twitter_tags' ), 10, 3 );
		parent::__construct( 'twitter' );
	}

	/**
	 * @return string
	 * @since 1.2.0
	 */
	public function get_module_icon() {
		return '';
	}

	/**
	 * @return array
	 * @since 1.1.0
	 */
	public function get_template_tags() {
		return array(
			'title'                           => __( 'Title', 'wp-content-pilot-pro' ),
			'content'                         => __( 'Content', 'wp-content-pilot-pro' ),
			'image_url'                       => __( 'Main image url', 'wp-content-pilot-pro' ),
			'source_url'                      => __( 'Source link', 'wp-content-pilot-pro' ),
			'date'                            => __( 'Published date', 'wp-content-pilot-pro' ),
			'id'                              => __( 'Tweet ID', 'wp-content-pilot-pro' ),
			'url'                             => __( 'Tweet URL', 'wp-content-pilot-pro' ),
			'images'                          => __( 'Images', 'wp-content-pilot-pro' ),
			'embed_html'                      => __( 'Embeded card', 'wp-content-pilot-pro' ),
			'tags'                            => __( 'Hash Tags', 'wp-content-pilot-pro' ),
			'retweet_count'                   => __( 'Retweet Count', 'wp-content-pilot-pro' ),
			'favorite_count'                  => __( 'Favorite Count', 'wp-content-pilot-pro' ),
			'reply_count'                     => __( 'Reply Count', 'wp-content-pilot-pro' ),
			'quote_count'                     => __( 'Quote Count', 'wp-content-pilot-pro' ),
			'author_id'                       => __( 'Author ID', 'wp-content-pilot-pro' ),
			'author_name'                     => __( 'Author Name', 'wp-content-pilot-pro' ),
			'author_screen_name'              => __( 'Author Screen Name', 'wp-content-pilot-pro' ),
			'author_description'              => __( 'Author Description', 'wp-content-pilot-pro' ),
			'author_url'                      => __( 'Author URL', 'wp-content-pilot-pro' ),
			'author_profile_image'            => __( 'Author Profile Image', 'wp-content-pilot-pro' ),
			'author_profile_background_image' => __( 'Author Profile Background Image', 'wp-content-pilot-pro' ),
		);
	}

	/**
	 * @return string
	 * @since 1.1.0
	 */
	public function get_default_template() {
		$template
			= <<<EOT
{images}<br>
{content}<br>
<a href="{url}">Source</a> by <a href="{author_url}" target="_blank">{author_name}</a>
EOT;

		return $template;
	}

	/**
	 * @param $post
	 */
	public function add_campaign_option_fields( $post ) {
		$this->get_twitter_keyword_suggestion();
		echo WPCP_HTML::checkbox_input( array(
			'label' => __( 'Twitter - Post hashtags as wordpress tags', 'wp-content-pilot-pro' ),
			'name'  => '_post_hash_tag_as_wp_tag',
		) );

		echo WPCP_HTML::checkbox_input( array(
			'label' => __( 'Twitter - Skip Retweets', 'wp-content-pilot-pro' ),
			'name'  => '_skip_retweets',
		) );
		echo WPCP_HTML::checkbox_input( array(
			'label' => __( 'Twitter - Skip in-reply-to tweets', 'wp-content-pilot-pro' ),
			'name'  => '_skip_in_reply_tweets',
		) );
		echo WPCP_HTML::checkbox_input( array(
			'label' => __( 'Twitter - Embed items as twitter cards (by default plain text)', 'wp-content-pilot-pro' ),
			'name'  => '_as_twitter_card',
		) );

	}

	/**
	 * @param $campaign_id
	 * @param $posted
	 */
	public function save_campaign_meta( $campaign_id, $posted ) {
		update_post_meta( $campaign_id, '_post_hash_tag_as_wp_tag', empty( $posted['_post_hash_tag_as_wp_tag'] ) ? '' : sanitize_key( $posted['_post_hash_tag_as_wp_tag'] ) );
		update_post_meta( $campaign_id, '_skip_retweets', empty( $posted['_skip_retweets'] ) ? '' : sanitize_key( $posted['_skip_retweets'] ) );
		update_post_meta( $campaign_id, '_skip_in_reply_tweets', empty( $posted['_skip_in_reply_tweets'] ) ? '' : sanitize_key( $posted['_skip_in_reply_tweets'] ) );
		update_post_meta( $campaign_id, '_as_twitter_card', empty( $posted['_as_twitter_card'] ) ? '' : sanitize_key( $posted['_as_twitter_card'] ) );
	}

	/**
	 * @param $sections
	 *
	 * @return array
	 * @since 1.1.0
	 */
	public function get_setting_section( $sections ) {
		$sections[] = [
			'id'    => 'wpcp_settings_twitter',
			'title' => __( 'Twitter Settings', 'wp-content-pilot-pro' )
		];

		return $sections;
	}

	/**
	 * @param $fields
	 *
	 * @return array
	 * @since 1.1.0
	 */
	public function get_setting_fields( $fields ) {
		$fields['wpcp_settings_twitter'] = array(
			array(
				'name'              => 'api_key',
				'label'             => __( 'API Key', 'wp-content-pilot-pro' ),
				'desc'              => sprintf( __( 'Twitter API key creation <a href="%s" target="_blank">guide</a>.', 'wp-content-pilot-pro' ), 'https://www.pluginever.com/docs/wp-content-pilot/twitter-campaign-settings/' ),
				'type'              => 'password',
				'sanitize_callback' => 'sanitize_text_field',
				'default'           => ''
			),
			array(
				'name'              => 'api_secret',
				'label'             => __( 'API Secret', 'wp-content-pilot-pro' ),
				'desc'              => sprintf( __( 'Twitter API Secret creation <a href="%s" target="_blank">guide</a>.', 'wp-content-pilot-pro' ), 'https://www.pluginever.com/docs/wp-content-pilot/twitter-campaign-settings/' ),
				'type'              => 'password',
				'sanitize_callback' => 'sanitize_text_field'
			),
		);

		return $fields;
	}

	/**
	 * @param int $campaign_id
	 *
	 * @return array|mixed|void|WP_Error
	 * @since 1.2.0
	 */
	public function get_post( $campaign_id ) {
		wpcp_logger()->info( __( 'Loaded Twitter Campaign', 'wp-content-pilot-pro' ), $campaign_id );

		$api_key    = wpcp_get_settings( 'api_key', 'wpcp_settings_twitter' );
		$api_secret = wpcp_get_settings( 'api_secret', 'wpcp_settings_twitter' );

		wpcp_logger()->info( __( 'Checking twitter api key and api secret for authentication', 'wp-content-pilot-pro' ), $campaign_id );
		if ( empty( $api_key ) || empty( $api_secret ) ) {
			wpcp_disable_campaign( $this->campaign_id );

			$notice = __( 'Twitter api key is not set.So, the campaign wont run, disabling campaign.', 'wp-content-pilot-pro' );
			wpcp_logger()->error( $notice, $this->campaign_id );

			return new WP_Error( 'missing-data', $notice );
		}

		$token = get_option( 'wpcp_twitter_token' );
		if ( empty( $token ) ) {
			$token = $this->get_token( $api_key, $api_secret );
			if ( is_wp_error( $token ) ) {
				wpcp_logger()->error( $token->get_error_message(), $campaign_id );

				return $token;
			}
			update_option( 'wpcp_twitter_token', $token );
		}

		$keywords = $this->get_campaign_meta( $campaign_id );
		if ( empty( $keywords ) ) {
			return new WP_Error( 'missing-data', __( 'Campaign do not have keyword to proceed, please set keyword', 'wp-content-pilot-pro' ) );
		}

		foreach ( $keywords as $keyword ) {
			wpcp_logger()->info( sprintf( __( 'Looping through keywords [ %s ]', 'wp-content-pilot-pro' ), $keyword ), $this->campaign_id );


			if ( $this->is_deactivated_key( $this->campaign_id, $keyword ) ) {
				wpcp_logger()->error( sprintf( __( 'The keyword is deactivated for 1 hr because last time could not find any article with keyword [%s]', 'wp-content-pilot-pro' ), $keyword ), $this->campaign_id );
				continue;
			}

			wpcp_logger()->info( __( 'Checking existing links in store...', 'wp-content-pilot-pro' ), $campaign_id );
			$links = $this->get_links( $keyword, $campaign_id );
			if ( empty( $links ) ) {
				wpcp_logger()->info( __( 'No generated links in store. Generating new links...', 'wp-content-pilot-pro' ), $campaign_id );
				$this->discover_links( $campaign_id, $keyword, $token );
				$links = $this->get_links( $keyword, $campaign_id );
			}


			foreach ( $links as $link ) {
				$this->update_link( $link->id, [ 'status' => 'failed' ] );
				$id       = basename( $link->url );
				$endpoint = add_query_arg( array(
					'include_entities' => 1,
					'tweet_mode'       => 'extended',
					'id'               => $id
				), 'https://api.twitter.com/1.1/statuses/show.json' );

				wpcp_logger()->info( sprintf( __( 'Requesting content from twitter links [%s]', 'wp-content-pilot-pro' ), $endpoint ), $campaign_id );

				$curl = $this->setup_curl();
				$curl->setHeader( 'Authorization', "Bearer $token" );
				$curl->get( $endpoint );
				if ( $curl->isError() ) {
					return new WP_Error( 'twitter-error', $curl->getErrorMessage() );
				}

				$response = $curl->getResponse();

				wpcp_logger()->info( __( 'Extracting tweet content from response', 'wp-content-pilot-pro' ), $campaign_id );
				$content = $response->full_text;

				wpcp_logger()->info( __( 'Extracting title', 'wp-content-pilot-pro' ), $campaign_id );
				$title = wpcp_remove_emoji( $content );
				$title = wpcp_strip_urls( $content );
				if ( function_exists( 'mb_substr' ) ) {
					$title = ( mb_substr( $content, 0, 80 ) );
				}
				$title = wpcp_clean_title( $title );
				$title = wpcp_generate_title_from_content( $content );

				wpcp_logger()->info( __( 'Extracting original post link', 'wp-content-pilot-pro' ), $campaign_id );
				//original post link
				$original_post_url = '';
				$original_post_url = @$response->entities->urls[0]->expanded_url;

				if ( trim( $original_post_url ) == '' ) {
					$original_post_url = $link->url;
				}

				//check images
				wpcp_logger()->info( __( 'Extracting images if any', 'wp-content-pilot-pro' ), $campaign_id );
				$image      = '';
				$all_images = '';
				if ( isset( $response->entities->media[0] ) ) {

					$media_img = $response->entities->media[0];
					if ( $media_img->type == 'photo' ) {
						$all_images .= '<img src="' . $media_img->media_url_https . '" /><br>';
						$image      = $media_img->media_url_https;
					}
				}

				wpcp_logger()->info( __( 'Extracting author url', 'wp-content-pilot-pro' ), $campaign_id );
				$author_url = $response->user->url;
				if ( trim( $response->user->url ) == '' ) {
					$author_url = 'https://twitter.com/intent/user?user_id=' . $response->user->id_str;
				}

				// VIDEO
				wpcp_logger()->info( __( 'Extracting video url if any', 'wp-content-pilot-pro' ), $campaign_id );
				$video_url = '';
				if ( isset( $response->extended_entities ) ) {
					if ( isset( $response->extended_entities->media ) ) {
						if ( isset( $response->extended_entities->media[0]->type ) && $response->extended_entities->media[0]->type == 'video' ) {
							$videoURL  = 'https://twitter.com/' . $response->user->screen_name . '/status/' . $response->id_str;
							$video_url = $videoURL;
						}
					}
				}

				// More images if exist
				wpcp_logger()->info( __( 'Extracting extra images', 'wp-content-pilot-pro' ), $campaign_id );
				if ( isset( $response->extended_entities ) ) {
					if ( isset( $response->extended_entities->media ) ) {
						foreach ( $response->extended_entities->media as $media_item ) {
							if ( $media_item->type == 'photo' ) {
								if ( ! stristr( $all_images, $media_item->media_url_https ) ) {
									$all_images .= '<br><img src="' . $media_item->media_url_https . '"/>';
								}
							}
						}
					}
				}
				if ( ! empty( $all_images ) ) {
					$content = $all_images . '<br><br>' . $content;
				}

				wpcp_logger()->info( __( 'Extracting tags', 'wp-content-pilot-pro' ), $campaign_id );
				$tags = '';
				// Add hashtags at WordPress tags if option is on.
				if ( isset( $response->entities->hashtags ) && count( $response->entities->hashtags ) ) {
					$hash_tags = wp_list_pluck( $response->entities->hashtags, 'text' );
					$tags      = wpcp_array_to_html( $hash_tags );

				}

				$date = date( 'Y-m-d', strtotime( $response->created_at ) );

				$embed_url      = 'https://api.twitter.com/1/statuses/oembed.json?url=https://twitter.com/zzz/status/' . $response->id;
				$embed_response = $curl->get( $embed_url );
				$embed_html     = $embed_response->html;
				if ( trim( $embed_html ) != '' && 'on' == wpcp_get_post_meta( $campaign_id, '_as_twitter_card', '' ) ) {
					$content = $embed_html;
				}

				//check clean title and perform title cleaning when checked
				$check_clean_title = wpcp_get_post_meta( $campaign_id, '_clean_title', 'off' );

				if ( 'on' == $check_clean_title ) {
					wpcp_logger()->info( __( 'Cleaning title', 'wp-content-pilot-pro' ), $campaign_id );
					$title = wpcp_clean_title( $title );
				} else {
					$title = html_entity_decode( $title, ENT_QUOTES );
				}

				wpcp_logger()->info( __( 'Combining all parts for article', 'wp-content-pilot-pro' ), $campaign_id );
				$article = array(
					'id'                              => $response->id,
					'url'                             => $link->url,
					'content'                         => $content,
					'source_url'                      => $original_post_url,
					'image_url'                       => $image,
					'images'                          => $all_images,
					'embed_html'                      => $embed_html,
					'retweet_count'                   => $response->retweet_count,
					'favorite_count'                  => $response->favorite_count,
					'reply_count'                     => isset( $response->reply_count ) ? $response->reply_count : 0,
					'quote_count'                     => isset( $response->quote_count ) ? $response->quote_count : 0,
					'author_id'                       => $response->user->id_str,
					'author_name'                     => $response->user->name,
					'author_screen_name'              => $response->user->screen_name,
					'author_description'              => $response->user->description,
					'author_url'                      => $author_url,
					'author_profile_image'            => str_replace( 'normal', '200x200', $response->user->profile_image_url ),
					'author_profile_background_image' => $response->user->profile_background_image_url,
					'date'                            => $date,
					'video_url'                       => $video_url,
					'title'                           => $title,
					'tags'                            => $tags,
				);

				wpcp_logger()->info( __( 'Article processed from campaign', 'wp-content-pilot-pro' ), $campaign_id );
				$this->update_link( $link->id, [ 'status' => 'success', 'title' => $title ] );

				return $article;
			}
		}

		$log_url = admin_url( '/edit.php?post_type=wp_content_pilot&page=wpcp-logs' );

		return new WP_Error( 'campaign-error', __( sprintf( 'No article generated check <a href="%s">log</a> for details.', $log_url ), 'wp-content-pilot-pro' ) );
	}

	/**
	 * @param $campaign_id
	 * @param $keyword
	 * @param $token
	 *
	 * @return int|WP_Error
	 * @since 1.2.0
	 */
	protected function discover_links( $campaign_id, $keyword, $token ) {
		$next_max_key = sanitize_key( '_next_max_' . $campaign_id . '_' . md5( $keyword ) );
		$next_max_id  = wpcp_get_post_meta( $campaign_id, $next_max_key, '' );
		wpcp_logger()->info( sprintf( __( 'Discovering twitter links keyword [%s] next max id [%s]', 'wp-content-pilot-pro' ), $keyword, $next_max_id ) );


		$api_url    = 'https://api.twitter.com/1.1/search/tweets.json';
		$query_args = array(
			'tweet_mode'       => 'extended',
			'q'                => urlencode( trim( $keyword ) ),
			'count'            => 50,
			'include_entities' => 1,
		);

		if ( ! empty( $next_max_id ) ) {
			$query_args['max_id'] = $next_max_id;
		}

		if ( stristr( $keyword, 'from:' ) ) {
			$screen_name = str_replace( 'from:', '', $keyword );
			unset( $query_args['q'] );
			$query_args['screen_name'] = $screen_name;
			$api_url                   = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
		}

		$endpoint = add_query_arg( $query_args, $api_url );
		wpcp_logger()->info( sprintf( __( "Searching for links [%s]", 'wp-content-pilot-pro' ), $endpoint ), $campaign_id );

		$curl = $this->setup_curl();
		$curl->setHeader( 'Authorization', "Bearer $token" );
		$curl->get( $endpoint );
		if ( $curl->isError() ) {
			return new WP_Error( 'twitter-error', $curl->getErrorMessage() );
		}

		wpcp_logger()->info( __( 'Getting response from request for links', 'wp-content-pilot-pro' ), $campaign_id );
		$response = $curl->getResponse();

		$items = $response;
		if ( ! stristr( $keyword, 'from:' ) ) {
			$items = $response->statuses;
		}

		if ( ! isset( $items ) || empty( $items ) || ! is_array( $items ) ) {
			$this->deactivate_key( $campaign_id, $keyword );
			$message = __( 'Could not find any matched data from twitter deactivating the key for an hour', 'wp-content-pilot-pro' );
			wpcp_logger()->error( $message, $campaign_id );

			return new WP_Error( 'no-links', $message );
		}

		$skip_retweets        = wpcp_get_post_meta( $campaign_id, '_skip_retweets', 0 );
		$skip_in_reply_tweets = wpcp_get_post_meta( $campaign_id, '_skip_in_reply_tweets', 0 );

		$max_id = 9999999999999999999999999999999999;
		wpcp_logger()->info( sprintf( __( 'Total Tweets Found [%d]', 'wp-content-pilot-pro' ), count( $items ) ) );

		$links = [];
		wpcp_logger()->info( __( 'Looping through links for storing..', 'wp-content-pilot-pro' ), $campaign_id );
		foreach ( $items as $item ) {
			//max_id
			if ( $item->id < $max_id ) {
				$max_id = $item->id;
			}

			$url = esc_url( 'https://twitter.com/' . $item->user->screen_name . '/statuses/' . $item->id_str );

			// If retweet and retweet skip option on, skip this tweet.
			if ( $skip_retweets && isset( $item->retweeted_status ) ) {
				wpcp_logger()->info( __( 'Retweet skipped...', 'wp-content-pilot-pro' ), $campaign_id );
				continue;
			}

			if ( isset( $item->retweeted_status ) ) {
				$item = $item->retweeted_status;
			}

			$content = $item->full_text;
			$title   = wpcp_generate_title_from_content( $content );

			if ( wpcp_is_duplicate_url( $url ) ) {
				continue;
			}

			$skip = apply_filters( 'wpcp_skip_duplicate_title', true, $title, $campaign_id );
			if ( $skip ) {
				continue;
			}


			$links[] = [
				'title'   => wpcp_remove_emoji( $title ),
				'url'     => $url,
				'camp_id' => $campaign_id,
				'for'     => $keyword,
			];
		}

		$total_inserted = $this->inset_links( $links );
		wpcp_logger()->info( sprintf( 'Total found links [%d] and accepted [%d] and rejected [%d]', count( $links ), $total_inserted, ( count( $links ) - $total_inserted ) ), $campaign_id );

		if ( empty( $items ) || ( count( $items ) == 1 && $max_id == $next_max_id ) ) {
			wpcp_logger()->info( 'Keyword does not have no more tweets deactivating keyword' );
			$this->deactivate_key( $campaign_id, $keyword, ( 30 * 24 * 60 * 60 ) );

			return new WP_Error( 'no-result', __( 'Keyword does not have no more tweets deactivating keyword', 'wp-content-pilot-pro' ) );
		}

		wpcp_update_post_meta( $campaign_id, $next_max_key, $max_id );

		return true;
	}


	/**
	 * @param $key
	 * @param $secret
	 *
	 * @return WP_Error
	 * @since 1.2.0
	 */
	protected function get_token( $key, $secret ) {
		$concated       = urlencode( $key ) . ':' . urlencode( $secret );
		$concatedBase64 = base64_encode( $concated );
		$url            = "https://api.twitter.com/oauth2/token";
		$curl           = $this->setup_curl();
		$curl->setHeader( 'Authorization', "Basic $concatedBase64" );
		$curl->setHeader( 'Content-Type', "application/x-www-form-urlencoded;charset=UTF-8" );
		$curl->post( $url, [ 'grant_type' => 'client_credentials' ] );
		if ( $curl->isError() ) {
			return new WP_Error( 'twitter-api-error', 'Could not generate twitter Access token' );
		}


		return $curl->getResponse()->access_token;
	}

	/**
	 * @param $post_id int
	 * @param $campaign_id int
	 * @param $article array
	 *
	 * @since 1.2.0
	 */
	public function maybe_set_twitter_tags( $post_id, $campaign_id, $article ) {

		if ( 'on' == get_post_meta( $campaign_id, '_post_hash_tag_as_wp_tag', true ) && ! empty( $article['tags'] ) ) {
			$tags = [];
			$dom  = wpcp_str_get_html( $article['tags'] );
			/* @var $node simple_html_dom_node */
			foreach ( $dom->find( 'li' ) as $node ) {
				if ( ! empty( $node->text() ) ) {
					$tags[] = $node->text();
				}
			}

			if ( ! empty( $tags ) ) {
				wpcp_set_post_terms( $tags, $post_id, 'post_tag' );
			}

		};
	}

	protected function get_twitter_keyword_suggestion() {
		?>
        <table>
            <thead>
            <tr>
                <td colspan="2"><strong><?php echo __( "Twitter Keywords hits", 'wp-content-pilot-pro' ); ?></strong></td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td><?php echo __( "from:pluginever", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "Tweets from person “pluginever”", 'wp-content-pilot-pro' ); ?>.</i></td>
            </tr>
            <tr>
                <td><?php echo __( "to:pluginever", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "sent to person “pluginever”.", 'wp-content-pilot-pro' ); ?></i></td>
            </tr>
            <tr>
                <td><?php echo __( "watching movie", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "containing both “watching” and “movie”.", 'wp-content-pilot-pro' ); ?></i></td>
            </tr>
            <tr>
                <td><?php echo __( "“happy hour”", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "containing the exact phrase “happy hour”.", 'wp-content-pilot-pro' ); ?></i>
                </td>
            </tr>
            <tr>
                <td><?php echo __( "love OR hate", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "containing either “love” or “hate” (or both).", 'wp-content-pilot-pro' ); ?></i>
                </td>
            </tr>
            <tr>
                <td><?php echo __( "beer -root", 'wp-content-pilot-pro' ); ?></td>
                <td><i>  <?php echo __( "containing “beer” but not “root”.", 'wp-content-pilot-pro' ); ?></i></td>
            </tr>
            <tr>
                <td><?php echo __( "#pluginever", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "containing the hashtag “pluginever”.", 'wp-content-pilot-pro' ); ?></i></td>
            </tr>
            <tr>
                <td><?php echo __( "@pluginever", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "referencing person “pluginever”.", 'wp-content-pilot-pro' ); ?></i></td>
            </tr>
            <tr>
                <td><?php echo __( "superhero since:2015-07-19", 'wp-content-pilot-pro' ); ?></td>
                <td>
                    <i> <?php echo __( "containing “superhero” and sent since date “2015-07-19” (year-month-day).", 'wp-content-pilot-pro' ); ?></i>
                </td>
            </tr>
            <tr>
                <td><?php echo __( "ftw until:2015-07-19", 'wp-content-pilot-pro' ); ?></td>
                <td>
                    <i> <?php echo __( "containing “ftw” and sent before the date “2015-07-19”.", 'wp-content-pilot-pro' ); ?></i>
                </td>
            </tr>
            <tr>
                <td><?php echo __( "movie -scary :)", 'wp-content-pilot-pro' ); ?></td>
                <td>
                    <i> <?php echo __( "containing “movie”, but not “scary”, and with a positive attitude.", 'wp-content-pilot-pro' ); ?></i>
                </td>
            </tr>
            <tr>
                <td><?php echo __( "flight :(", 'wp-content-pilot-pro' ); ?></td>
                <td>
                    <i> <?php echo __( "containing “flight” and with a negative attitude.", 'wp-content-pilot-pro' ); ?></i>
                </td>
            </tr>
            <tr>
                <td><?php echo __( "traffic ?", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "containing “traffic” and asking a question.", 'wp-content-pilot-pro' ); ?></i>
                </td>
            </tr>
            <tr>
                <td><?php echo __( "hilarious filter:links", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "containing “hilarious” and linking to URL.", 'wp-content-pilot-pro' ); ?></i>
                </td>
            </tr>
            <tr>
                <td><?php echo __( "news source:twitterfeed", 'wp-content-pilot-pro' ); ?></td>
                <td><i> <?php echo __( "containing “news” and entered via TwitterFeed", 'wp-content-pilot-pro' ); ?></i>
                </td>
            </tr>
            </tbody>
        </table>
		<?php
	}

	/**
	 * Main WPCP_Twitter Instance.
	 *
	 * Ensures only one instance of WPCP_Twitter is loaded or can be loaded.
	 *
	 * @return WPCP_Twitter Main instance
	 * @since 1.1.0
	 * @static
	 */
	public static function instance() {
		if ( is_null( self::$_instance ) ) {
			self::$_instance = new self();
		}

		return self::$_instance;
	}

}

WPCP_Twitter::instance();
