# topic/1.0.8/index.php

Topic SEO Content Optimization Tool, version 1.0.8. 314 lines.

- Page: https://pluginprobe.com/plugins/topic/1.0.8/code/index.php
- Raw: https://pluginprobe.com/plugins/topic/1.0.8/raw/index.php
- Modified: 2021-11-05T16:28:26+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.8/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.8
  */ 
if( ! defined( 'ABSPATH') ) {
    exit;
}

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' )
  );
}
add_action( 'enqueue_block_editor_assets', 'topic_enqueue_assets' );

class useTopicSeo {

	
    public function __construct() {
			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('wp_ajax_get_first_click_template_topic', array($this, 'get_first_click_template_topic'));

			add_action('wp_ajax_logout_topic_user', array($this, 'logout_topic_user_func'));
			add_action('wp_ajax_brief_detail_page', array($this, 'brief_detail_page'));
			add_action('wp_ajax_brief_detail_page_back', array($this, 'brief_detail_page_back'));
			add_action('wp_ajax_brief_detail_page_grades_update', array($this, 'brief_detail_page_grades_update'));
			add_filter( 'tiny_mce_before_init', array($this, 'add_js_for_onchange_usetopic') );
			add_filter( 'wp_ajax_topic_keyword_detail_view', array($this, 'topic_keyword_detail_view') );	
			add_filter( 'wp_ajax_search_briefs_by_keyword', array($this, 'search_briefs_by_keyword') );	

    }

	
	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_classic() {
		  wp_enqueue_script(
				'topic-gutenberg-sidebar-classic',
				plugins_url( 'classic-editor/index-classic.js', __FILE__ ),
				array( 'wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element' ),time()
		  );
		      wp_enqueue_style('topic-classic-sidebar', plugins_url( 'classic-editor/classic.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_first_click_template_topic(){
		if( current_user_can('administrator') || current_user_can('manage_options') ) {
			include dirname(__FILE__) .'/api/usetopicapi.php';
			$UseTopicApi 	= new UseTopicAPI();


			$preloginToken = get_option('usetopicapi_token');
			if(!empty($preloginToken)){
				$allBriefs		=  $UseTopicApi->getBriefsbyTopicToken($preloginToken);
				if(is_object( json_decode( $allBriefs ) )){

					ob_start();
					include  dirname(__FILE__) .'/templates/briefs.php';
					$data =  ob_get_clean();
					echo  $data ;

				}else{

					update_option('usetopicapi_token','');
					update_option('usetopicapi_email','');
					ob_start();
					include  dirname(__FILE__) .'/templates/login.php';
					$data =  ob_get_clean();
					echo  $data ;

				}
				wp_die();
			}

			if(isset($_POST['email']) && isset($_POST['password'])){
				$loginData		= $UseTopicApi->authenticateUsetopicUser($_POST['email'], $_POST['password']);
				$res 					=  json_decode( $loginData );
				if(property_exists($res , 'error')){
					wp_send_json([
						'success' => false,
						'message' => $res->error
						]);

				}elseif(property_exists($res , 'token')){

						//update to database
						update_option('usetopicapi_token', $res->token);
						update_option('usetopicapi_id', $res->id);
						update_option('usetopicapi_email', $_POST['email']);
						$allBriefs		=  $UseTopicApi->getBriefsbyTopicToken($res->token);

						ob_start();
						include  dirname(__FILE__) .'/templates/briefs.php';
						$html =  ob_get_clean();

						wp_send_json([
						'success' => true,
						'html' => $html
						]);

				}else{
						wp_send_json([
						'success' => false,
						'message' => 'invalid username or password'
						]);
				} 

			}else{

				ob_start();
				include  dirname(__FILE__) .'/templates/login.php';
				$data =  ob_get_clean();
				echo  $data ;
			}

			die();
		}
	}

	public function logout_topic_user_func(){
		if( current_user_can('administrator') || current_user_can('manage_options') ) {
		if(isset($_POST['usetopiclogout']) && $_POST['usetopiclogout'] == true){
					update_option('usetopicapi_token','');
					update_option('usetopicapi_email','');
					ob_start();
					include  dirname(__FILE__) .'/templates/login.php';
					$data =  ob_get_clean();
					echo  $data ;

		}
	}
		wp_die();
	}
	public function brief_detail_page(){
		if( current_user_can('administrator') || current_user_can('manage_options') ) {
			include dirname(__FILE__) .'/api/usetopicapi.php';
			$UseTopicApi 		= new UseTopicAPI();

			if(isset($_POST['briefID']) && !empty( $_POST['briefID'] ) ){
					$briefID = $_POST['briefID'];
					$briefContent = $_POST['content'];
					$briefToken  	= get_option('usetopicapi_token');
					$briefDetail	=  $UseTopicApi->getBriefDetailByID( $briefID, $briefToken );
					$briefFromURL = false;

					ob_start();
					include  dirname(__FILE__) .'/templates/brief-detail.php';
					$data =  ob_get_clean();

					wp_send_json([
						'success' => true,
						'html' => $data,
						'briefdetailar'=> json_encode( $rcTopic )
					]);

			}elseif( isset($_POST['burl']) && !empty( $_POST['burl']) ){

					update_option('usetopicapi_token', '');
					update_option('usetopicapi_id', '');
				  update_option('usetopicapi_email', '');
				  $briefFromURL = true;

				  $burl 		 = $_POST['burl'];
				  $briefPath =  parse_url( $burl )['path'];
				  if( !empty( $briefPath ) ){

						$briefid = explode( "/", $briefPath )[2];
						if(!empty($briefid)){

							$briefDetail		=  $UseTopicApi->getBriefDetailByURL( $briefid );
							if( isset(json_decode($briefDetail, true)['error']) && !empty( json_decode($briefDetail, true)['error'] ) ){
									wp_send_json([
										'success' => false,
										'message' => 'Invalid URL, Please make sure brief is public'
									]);
							}else{

								ob_start();
								include  dirname(__FILE__) .'/templates/brief-detail.php';
								$data =  ob_get_clean();

								wp_send_json([
									'success' => true,
									'html' => $data,
									'briefid' => $briefid, 
									'briefdetailar'=> json_encode( $rcTopic )
								]);
							}

						}else{
							wp_send_json([
								'success' => false,
								'message' => 'Invalid URL, Please make sure brief is public'
							]);
						}
					}else{
						wp_send_json([
								'success' => false,
								'message' => 'Invalid URL, Please make sure brief is public'
							]);
					}

			}
		}
		wp_die();
	}

	public function brief_detail_page_back(){
		if( current_user_can('administrator') || current_user_can('manage_options') ) {
					include dirname(__FILE__) .'/api/usetopicapi.php';
					$UseTopicApi 		= new UseTopicAPI();
					$preloginToken 	= get_option('usetopicapi_token');
					$allBriefs			=  $UseTopicApi->getBriefsbyTopicToken($preloginToken);
					ob_start();
					include  dirname(__FILE__) .'/templates/briefs.php';
					$data =  ob_get_clean();
					echo  $data ;
		}
		wp_die();
	}

	public function brief_detail_page_grades_update(){
		if( current_user_can('administrator') || current_user_can('manage_options') ) {
			include dirname(__FILE__) .'/api/usetopicapi.php';
			$UseTopicApi 		= new UseTopicAPI();

			if(isset($_POST['briefID']) && !empty( $_POST['briefID'] ) ){
					if( isset($_POST['byURLBF']) && $_POST['byURLBF'] == 'yes' ){
						$briefID 				= $_POST['briefID'];
						$briefContent 	= $_POST['content'];
						$briefDetailUP	=  $UseTopicApi->getBriefUpdatedReportURL($briefID, $briefContent);
						echo $briefDetailUP;

					}else{
						$briefID 				= $_POST['briefID'];
						$briefContent 	= $_POST['content'];
						$briefToken  		= get_option('usetopicapi_token');
						$briefDetailUP	=  $UseTopicApi->getBriefUpdatedReport($briefID, $briefToken, $briefContent);
						echo $briefDetailUP;
					}
					

			}
		}
		wp_die();
	}
	public function topic_keyword_detail_view(){
		if( current_user_can('administrator') || current_user_can('manage_options') ) {
			if( isset($_POST['usetopicBriefArray']) ){
					$rcTopics  = $_POST['usetopicBriefArray'];
					$keyIndex	 = $_POST['indexval'];
					$keystatus = $_POST['keystatus'];
					ob_start();
					include  dirname(__FILE__) .'/templates/topic-keyword-detail.php';
					$data =  ob_get_clean();
					echo  $data ;

			}
		}
		wp_die();
	}
	public function search_briefs_by_keyword(){
		if( current_user_can('administrator') || current_user_can('manage_options') ) {
			include dirname(__FILE__) .'/api/usetopicapi.php';
			$UseTopicApi 		= new UseTopicAPI();
			if( isset($_POST['search']) ){
					$search  			= $_POST['search'];
					$briefToken 	= get_option('usetopicapi_token');
					$allBriefs		=  $UseTopicApi->getBriefsBySearch( $search, $briefToken );
					ob_start();
					include  dirname(__FILE__) .'/templates/search.php';
					$data =  ob_get_clean();
					echo $data ;

			}
		}
		wp_die();
	}

	
	
	public function add_js_for_onchange_usetopic( $initArray ) {
    $initArray['setup'] = 'function(ed){
      ed.on("change", function(ed) {
        updateUsetopicFrontGrades();
      });
    }';
    return $initArray;
  }

}
 
$wpUseTopic= new useTopicSeo();

```
