| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Topic |
| 4 |
* Plugin URI: https://www.usetopic.com/ |
| 5 |
* Description: Topic helps editors and agencies create content briefs in half the time. |
| 6 |
* Author: Topic |
| 7 |
* License: GPL v2 or later |
| 8 |
* License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 9 |
* Version: 1.0.11 |
| 10 |
*/ |
| 11 |
if( ! defined( 'ABSPATH') ) { |
| 12 |
exit; |
| 13 |
} |
| 14 |
|
| 15 |
function topic_enqueue_assets() { |
| 16 |
wp_enqueue_script( |
| 17 |
'topic-gutenberg-sidebar', |
| 18 |
plugins_url( 'build/index.js', __FILE__ ), |
| 19 |
array( 'wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element' ) |
| 20 |
); |
| 21 |
} |
| 22 |
add_action( 'enqueue_block_editor_assets', 'topic_enqueue_assets' ); |
| 23 |
|
| 24 |
class useTopicSeo { |
| 25 |
|
| 26 |
|
| 27 |
public function __construct() { |
| 28 |
add_action( 'post_submitbox_misc_actions', array($this, 'add_usetopic_button_classic_editor') ); |
| 29 |
add_action( 'admin_enqueue_scripts', array($this, 'topic_enqueue_assets_classic') ); |
| 30 |
add_action('admin_footer', array($this, 'useTopicSeo_sidebar_box')); |
| 31 |
add_action('wp_ajax_get_first_click_template_topic', array($this, 'get_first_click_template_topic')); |
| 32 |
|
| 33 |
add_action('wp_ajax_logout_topic_user', array($this, 'logout_topic_user_func')); |
| 34 |
add_action('wp_ajax_brief_detail_page', array($this, 'brief_detail_page')); |
| 35 |
add_action('wp_ajax_brief_detail_page_back', array($this, 'brief_detail_page_back')); |
| 36 |
add_action('wp_ajax_brief_detail_page_grades_update', array($this, 'brief_detail_page_grades_update')); |
| 37 |
// add_filter( 'tiny_mce_before_init', array($this, 'add_js_for_onchange_usetopic') ); |
| 38 |
add_filter( 'wp_ajax_topic_keyword_detail_view', array($this, 'topic_keyword_detail_view') ); |
| 39 |
add_filter( 'wp_ajax_search_briefs_by_keyword', array($this, 'search_briefs_by_keyword') ); |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
public function add_usetopic_button_classic_editor(){ |
| 45 |
$html = '<div id="major-publishing-actions-use-topic" style="overflow:hidden"><p>'.__( 'Topic SEO Content Optimization Tool', 'usetopic-plugin' ).'</p>'; |
| 46 |
$html .= '<div id="publishing-action-use-topic">'; |
| 47 |
$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>'; |
| 48 |
$html .= '</div>'; |
| 49 |
$html .= '</div>'; |
| 50 |
echo $html; |
| 51 |
} |
| 52 |
|
| 53 |
public function topic_enqueue_assets_classic() { |
| 54 |
wp_enqueue_script( |
| 55 |
'topic-gutenberg-sidebar-classic', |
| 56 |
plugins_url( 'build/index-classic.js', __FILE__ ), |
| 57 |
array( 'wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element' ),time() |
| 58 |
); |
| 59 |
wp_enqueue_style('topic-classic-sidebar', plugins_url( 'classic-editor/classic.css', __FILE__ ), array(), time(), 'all'); |
| 60 |
} |
| 61 |
|
| 62 |
public function useTopicSeo_sidebar_box($data) { |
| 63 |
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>'; |
| 64 |
} |
| 65 |
|
| 66 |
public function get_first_click_template_topic(){ |
| 67 |
include dirname(__FILE__) .'/api/usetopicapi.php'; |
| 68 |
$UseTopicApi = new UseTopicAPI(); |
| 69 |
|
| 70 |
|
| 71 |
$preloginToken = get_option('usetopicapi_token'); |
| 72 |
if(!empty($preloginToken)){ |
| 73 |
$allBriefs = $UseTopicApi->getBriefsbyTopicToken($preloginToken); |
| 74 |
if(is_object( json_decode( $allBriefs ) )){ |
| 75 |
|
| 76 |
ob_start(); |
| 77 |
include dirname(__FILE__) .'/templates/briefs.php'; |
| 78 |
$data = ob_get_clean(); |
| 79 |
echo $data ; |
| 80 |
|
| 81 |
}else{ |
| 82 |
|
| 83 |
update_option('usetopicapi_token',''); |
| 84 |
update_option('usetopicapi_email',''); |
| 85 |
ob_start(); |
| 86 |
include dirname(__FILE__) .'/templates/login.php'; |
| 87 |
$data = ob_get_clean(); |
| 88 |
echo $data ; |
| 89 |
|
| 90 |
} |
| 91 |
wp_die(); |
| 92 |
} |
| 93 |
|
| 94 |
if(isset($_POST['email']) && isset($_POST['password'])){ |
| 95 |
$loginData = $UseTopicApi->authenticateUsetopicUser($_POST['email'], $_POST['password']); |
| 96 |
$res = json_decode( $loginData ); |
| 97 |
if(property_exists($res , 'error')){ |
| 98 |
wp_send_json([ |
| 99 |
'success' => false, |
| 100 |
'message' => $res->error |
| 101 |
]); |
| 102 |
|
| 103 |
}elseif(property_exists($res , 'token')){ |
| 104 |
|
| 105 |
//update to database |
| 106 |
update_option('usetopicapi_token', $res->token); |
| 107 |
update_option('usetopicapi_id', $res->id); |
| 108 |
update_option('usetopicapi_email', $_POST['email']); |
| 109 |
$allBriefs = $UseTopicApi->getBriefsbyTopicToken($res->token); |
| 110 |
|
| 111 |
ob_start(); |
| 112 |
include dirname(__FILE__) .'/templates/briefs.php'; |
| 113 |
$html = ob_get_clean(); |
| 114 |
|
| 115 |
wp_send_json([ |
| 116 |
'success' => true, |
| 117 |
'html' => $html |
| 118 |
]); |
| 119 |
|
| 120 |
}else{ |
| 121 |
wp_send_json([ |
| 122 |
'success' => false, |
| 123 |
'message' => 'invalid username or password' |
| 124 |
]); |
| 125 |
} |
| 126 |
|
| 127 |
}else{ |
| 128 |
|
| 129 |
ob_start(); |
| 130 |
include dirname(__FILE__) .'/templates/login.php'; |
| 131 |
$data = ob_get_clean(); |
| 132 |
echo $data ; |
| 133 |
} |
| 134 |
|
| 135 |
die(); |
| 136 |
} |
| 137 |
|
| 138 |
public function logout_topic_user_func(){ |
| 139 |
if(isset($_POST['usetopiclogout']) && $_POST['usetopiclogout'] == true){ |
| 140 |
update_option('usetopicapi_token',''); |
| 141 |
update_option('usetopicapi_email',''); |
| 142 |
ob_start(); |
| 143 |
include dirname(__FILE__) .'/templates/login.php'; |
| 144 |
$data = ob_get_clean(); |
| 145 |
echo $data ; |
| 146 |
|
| 147 |
} |
| 148 |
wp_die(); |
| 149 |
} |
| 150 |
public function brief_detail_page(){ |
| 151 |
include dirname(__FILE__) .'/api/usetopicapi.php'; |
| 152 |
$UseTopicApi = new UseTopicAPI(); |
| 153 |
|
| 154 |
if(isset($_POST['briefID']) && !empty( $_POST['briefID'] ) ){ |
| 155 |
$briefID = $_POST['briefID']; |
| 156 |
$briefContent = $_POST['content']; |
| 157 |
$briefToken = get_option('usetopicapi_token'); |
| 158 |
$briefDetail = $UseTopicApi->getBriefDetailByID( $briefID, $briefToken ); |
| 159 |
$briefFromURL = false; |
| 160 |
|
| 161 |
ob_start(); |
| 162 |
include dirname(__FILE__) .'/templates/brief-detail.php'; |
| 163 |
$data = ob_get_clean(); |
| 164 |
|
| 165 |
wp_send_json([ |
| 166 |
'success' => true, |
| 167 |
'html' => $data, |
| 168 |
'briefdetailar'=> json_encode( $rcTopic ) |
| 169 |
]); |
| 170 |
|
| 171 |
}elseif( isset($_POST['burl']) && !empty( $_POST['burl']) ){ |
| 172 |
|
| 173 |
update_option('usetopicapi_token', ''); |
| 174 |
update_option('usetopicapi_id', ''); |
| 175 |
update_option('usetopicapi_email', ''); |
| 176 |
$briefFromURL = true; |
| 177 |
|
| 178 |
$burl = $_POST['burl']; |
| 179 |
$briefPath = parse_url( $burl )['path']; |
| 180 |
if( !empty( $briefPath ) ){ |
| 181 |
|
| 182 |
$briefid = explode( "/", $briefPath )[2]; |
| 183 |
if(!empty($briefid)){ |
| 184 |
|
| 185 |
$briefDetail = $UseTopicApi->getBriefDetailByURL( $briefid ); |
| 186 |
if( isset(json_decode($briefDetail, true)['error']) && !empty( json_decode($briefDetail, true)['error'] ) ){ |
| 187 |
wp_send_json([ |
| 188 |
'success' => false, |
| 189 |
'message' => 'Invalid URL, Please make sure brief is public' |
| 190 |
]); |
| 191 |
}else{ |
| 192 |
|
| 193 |
ob_start(); |
| 194 |
include dirname(__FILE__) .'/templates/brief-detail.php'; |
| 195 |
$data = ob_get_clean(); |
| 196 |
|
| 197 |
wp_send_json([ |
| 198 |
'success' => true, |
| 199 |
'html' => $data, |
| 200 |
'briefid' => $briefid, |
| 201 |
'briefdetailar'=> json_encode( $rcTopic ) |
| 202 |
]); |
| 203 |
} |
| 204 |
|
| 205 |
}else{ |
| 206 |
wp_send_json([ |
| 207 |
'success' => false, |
| 208 |
'message' => 'Invalid URL, Please make sure brief is public' |
| 209 |
]); |
| 210 |
} |
| 211 |
}else{ |
| 212 |
wp_send_json([ |
| 213 |
'success' => false, |
| 214 |
'message' => 'Invalid URL, Please make sure brief is public' |
| 215 |
]); |
| 216 |
} |
| 217 |
|
| 218 |
} |
| 219 |
wp_die(); |
| 220 |
} |
| 221 |
|
| 222 |
public function brief_detail_page_back(){ |
| 223 |
include dirname(__FILE__) .'/api/usetopicapi.php'; |
| 224 |
$UseTopicApi = new UseTopicAPI(); |
| 225 |
$preloginToken = get_option('usetopicapi_token'); |
| 226 |
$allBriefs = $UseTopicApi->getBriefsbyTopicToken($preloginToken); |
| 227 |
ob_start(); |
| 228 |
include dirname(__FILE__) .'/templates/briefs.php'; |
| 229 |
$data = ob_get_clean(); |
| 230 |
echo $data ; |
| 231 |
|
| 232 |
wp_die(); |
| 233 |
} |
| 234 |
|
| 235 |
public function brief_detail_page_grades_update(){ |
| 236 |
include dirname(__FILE__) .'/api/usetopicapi.php'; |
| 237 |
$UseTopicApi = new UseTopicAPI(); |
| 238 |
|
| 239 |
if(isset($_POST['briefID']) && !empty( $_POST['briefID'] ) ){ |
| 240 |
if( isset($_POST['byURLBF']) && $_POST['byURLBF'] == 'yes' ){ |
| 241 |
$briefID = $_POST['briefID']; |
| 242 |
$briefContent = $_POST['content']; |
| 243 |
$briefDetailUP = $UseTopicApi->getBriefUpdatedReportURL($briefID, $briefContent); |
| 244 |
echo $briefDetailUP; |
| 245 |
|
| 246 |
}else{ |
| 247 |
$briefID = $_POST['briefID']; |
| 248 |
$briefContent = $_POST['content']; |
| 249 |
$briefToken = get_option('usetopicapi_token'); |
| 250 |
$briefDetailUP = $UseTopicApi->getBriefUpdatedReport($briefID, $briefToken, $briefContent); |
| 251 |
echo $briefDetailUP; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
} |
| 256 |
wp_die(); |
| 257 |
} |
| 258 |
public function topic_keyword_detail_view(){ |
| 259 |
if( isset($_POST['usetopicBriefArray']) ){ |
| 260 |
$rcTopics = $_POST['usetopicBriefArray']; |
| 261 |
$keyIndex = $_POST['indexval']; |
| 262 |
$keystatus = $_POST['keystatus']; |
| 263 |
ob_start(); |
| 264 |
include dirname(__FILE__) .'/templates/topic-keyword-detail.php'; |
| 265 |
$data = ob_get_clean(); |
| 266 |
echo $data ; |
| 267 |
|
| 268 |
} |
| 269 |
wp_die(); |
| 270 |
} |
| 271 |
public function search_briefs_by_keyword(){ |
| 272 |
include dirname(__FILE__) .'/api/usetopicapi.php'; |
| 273 |
$UseTopicApi = new UseTopicAPI(); |
| 274 |
if( isset($_POST['search']) ){ |
| 275 |
$search = $_POST['search']; |
| 276 |
$briefToken = get_option('usetopicapi_token'); |
| 277 |
$allBriefs = $UseTopicApi->getBriefsBySearch( $search, $briefToken ); |
| 278 |
ob_start(); |
| 279 |
include dirname(__FILE__) .'/templates/search.php'; |
| 280 |
$data = ob_get_clean(); |
| 281 |
echo $data ; |
| 282 |
|
| 283 |
} |
| 284 |
wp_die(); |
| 285 |
} |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
public function add_js_for_onchange_usetopic( $initArray ) { |
| 290 |
$initArray['setup'] = 'function(ed){ |
| 291 |
ed.on("change", function(ed) { |
| 292 |
updateUsetopicFrontGrades(); |
| 293 |
}); |
| 294 |
}'; |
| 295 |
return $initArray; |
| 296 |
} |
| 297 |
|
| 298 |
} |
| 299 |
|
| 300 |
$wpUseTopic= new useTopicSeo(); |
| 301 |
|