# topic/1.0.24/index.php

Topic SEO Content Optimization Tool, version 1.0.24. 102 lines.

- Page: https://pluginprobe.com/plugins/topic/1.0.24/code/index.php
- Raw: https://pluginprobe.com/plugins/topic/1.0.24/raw/index.php
- Modified: 2023-09-05T21:33:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/topic/1.0.24/code/index.php#L10-L20`.

```php
<?php
/**
  * Plugin Name: Topic
  * Plugin URI: https://www.usetopic.com/
  * Description: Topic helps editors and agencies create content briefs in half the time.
  * Author: Topic
  * License: GPL v2 or later
  * License URI: https://www.gnu.org/licenses/gpl-2.0.html
  * Version: 1.0.24
  */ 
if( ! defined( 'ABSPATH') ) {
    exit;
}


class useTopicSeo {

	
    public function __construct() {
    	global $pagenow;
    	if($pagenow == 'post.php' || $pagenow == 'post-new.php'){
				add_action( 'post_submitbox_misc_actions', array($this, 'add_usetopic_button_classic_editor') );
				add_action( 'admin_enqueue_scripts', array($this, 'topic_enqueue_assets_classic') );
				add_action('admin_footer', array($this, 'useTopicSeo_sidebar_box'));
				add_action( 'enqueue_block_editor_assets', array($this,'topic_enqueue_assets') );
			}
			add_action('wp_ajax_get_permalink_for_post_id', array($this, 'get_permalink_for_post_id'));
			add_action('wp_ajax_search_posts', array($this, 'search_posts'));
    }

	
	public function add_usetopic_button_classic_editor(){
			$html  = '<div id="major-publishing-actions-use-topic" style="overflow:hidden"><p>'.__( 'Topic SEO Content Optimization Tool', 'usetopic-plugin' ).'</p>';
			$html .= '<div id="publishing-action-use-topic">';
			$html .= '<button type="button" aria-pressed="true" aria-expanded="true" id="usetopicMain" class="components-button is-pressed has-icon" aria-label="Topic SEO Content Optimization Tool">Grade Content</button>';
			$html .= '</div>';
			$html .= '</div>';
			echo $html;
	}

	public function topic_enqueue_assets() {
	  wp_enqueue_script(
	    'topic-gutenberg-sidebar',
	    plugins_url( 'build/index.js', __FILE__ ),
	    array( 'wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element' )
	  );
	  wp_enqueue_style('topic-sidebar-global', plugins_url( 'build/index.css', __FILE__ ), array(), time(), 'all');
	}
	
	public function topic_enqueue_assets_classic() {
		  wp_enqueue_script(
				'topic-gutenberg-sidebar-classic',
				plugins_url( 'build/index-classic.js', __FILE__ ), array('wp-plugins'), time(), true
		  );
		  wp_enqueue_style('topic-classic-sidebar', plugins_url( 'classic-editor/classic.css', __FILE__ ), array(), time(), 'all');
		  wp_enqueue_style('topic-sidebar-global', plugins_url( 'build/index.css', __FILE__ ), array(), time(), 'all');
	}
	
	public function useTopicSeo_sidebar_box($data) {
		 echo '<div id="usetopicData"><div class="closeTopicdata"><strong>'.__( 'Topic SEO Content Optimization Tool', 'usetopic-plugin' ).'</strong><button type="button" class="close" aria-label="Close plugin"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true" focusable="false"><path d="M12 13.06l3.712 3.713 1.061-1.06L13.061 12l3.712-3.712-1.06-1.06L12 10.938 8.288 7.227l-1.061 1.06L10.939 12l-3.712 3.712 1.06 1.061L12 13.061z"></path></svg><p class="usetopic-tooltip">Close Plugin</p></button></div><div class="content"></div></div>';
	}

	public function get_permalink_for_post_id(){
		if(isset($_POST['post_id'])){
			$post_id = $_POST['post_id'];
			$permalink = get_permalink(intval($post_id));

			wp_send_json([
				'permalink' => $permalink
			]);
		}
		wp_die();
	}

	public function search_posts(){
		if(isset($_POST['s'])){
			$s = $_POST['s'];

			global $wpdb;
			$myposts = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND post_title LIKE '%s'", '%'. $wpdb->esc_like( $s ) .'%') );
			$post_array = array();
			foreach ( $myposts as $mypost ) 
			{
			    // $post = get_post($mypost);
					$permalink = get_permalink(intval($mypost->ID));
					$mypost->permalink = $permalink;
					$mypost->post_content = "";
			    array_push($post_array, $mypost);
			}

			wp_send_json([
				'posts' => $post_array
			]);
		}
		wp_die();
	}


}
 
$wpUseTopic= new useTopicSeo();

```
