PluginProbe
Topic SEO Content Optimization Tool / 1.0.7
Topic SEO Content Optimization Tool v1.0.7
1.0.43 1.0.42 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.3 1.0.31 1.0.32 All 40 releases
topic / index.php

index.php in Topic SEO Content Optimization Tool 1.0.7, at index.php

314 lines 10.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.7
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( 'classic-editor/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 if( current_user_can('administrator') || current_user_can('manage_options') ) {
68 include dirname(__FILE__) .'/api/usetopicapi.php';
69 $UseTopicApi = new UseTopicAPI();
70
71
72 $preloginToken = get_option('usetopicapi_token');
73 if(!empty($preloginToken)){
74 $allBriefs = $UseTopicApi->getBriefsbyTopicToken($preloginToken);
75 if(is_object( json_decode( $allBriefs ) )){
76
77 ob_start();
78 include dirname(__FILE__) .'/templates/briefs.php';
79 $data = ob_get_clean();
80 echo $data ;
81
82 }else{
83
84 update_option('usetopicapi_token','');
85 update_option('usetopicapi_email','');
86 ob_start();
87 include dirname(__FILE__) .'/templates/login.php';
88 $data = ob_get_clean();
89 echo $data ;
90
91 }
92 wp_die();
93 }
94
95 if(isset($_POST['email']) && isset($_POST['password'])){
96 $loginData = $UseTopicApi->authenticateUsetopicUser($_POST['email'], $_POST['password']);
97 $res = json_decode( $loginData );
98 if(property_exists($res , 'error')){
99 wp_send_json([
100 'success' => false,
101 'message' => $res->error
102 ]);
103
104 }elseif(property_exists($res , 'token')){
105
106 //update to database
107 update_option('usetopicapi_token', $res->token);
108 update_option('usetopicapi_id', $res->id);
109 update_option('usetopicapi_email', $_POST['email']);
110 $allBriefs = $UseTopicApi->getBriefsbyTopicToken($res->token);
111
112 ob_start();
113 include dirname(__FILE__) .'/templates/briefs.php';
114 $html = ob_get_clean();
115
116 wp_send_json([
117 'success' => true,
118 'html' => $html
119 ]);
120
121 }else{
122 wp_send_json([
123 'success' => false,
124 'message' => 'invalid username or password'
125 ]);
126 }
127
128 }else{
129
130 ob_start();
131 include dirname(__FILE__) .'/templates/login.php';
132 $data = ob_get_clean();
133 echo $data ;
134 }
135
136 die();
137 }
138 }
139
140 public function logout_topic_user_func(){
141 if( current_user_can('administrator') || current_user_can('manage_options') ) {
142 if(isset($_POST['usetopiclogout']) && $_POST['usetopiclogout'] == true){
143 update_option('usetopicapi_token','');
144 update_option('usetopicapi_email','');
145 ob_start();
146 include dirname(__FILE__) .'/templates/login.php';
147 $data = ob_get_clean();
148 echo $data ;
149
150 }
151 }
152 wp_die();
153 }
154 public function brief_detail_page(){
155 if( current_user_can('administrator') || current_user_can('manage_options') ) {
156 include dirname(__FILE__) .'/api/usetopicapi.php';
157 $UseTopicApi = new UseTopicAPI();
158
159 if(isset($_POST['briefID']) && !empty( $_POST['briefID'] ) ){
160 $briefID = $_POST['briefID'];
161 $briefContent = $_POST['content'];
162 $briefToken = get_option('usetopicapi_token');
163 $briefDetail = $UseTopicApi->getBriefDetailByID( $briefID, $briefToken );
164 $briefFromURL = false;
165
166 ob_start();
167 include dirname(__FILE__) .'/templates/brief-detail.php';
168 $data = ob_get_clean();
169
170 wp_send_json([
171 'success' => true,
172 'html' => $data,
173 'briefdetailar'=> json_encode( $rcTopic )
174 ]);
175
176 }elseif( isset($_POST['burl']) && !empty( $_POST['burl']) ){
177
178 update_option('usetopicapi_token', '');
179 update_option('usetopicapi_id', '');
180 update_option('usetopicapi_email', '');
181 $briefFromURL = true;
182
183 $burl = $_POST['burl'];
184 $briefPath = parse_url( $burl )['path'];
185 if( !empty( $briefPath ) ){
186
187 $briefid = explode( "/", $briefPath )[2];
188 if(!empty($briefid)){
189
190 $briefDetail = $UseTopicApi->getBriefDetailByURL( $briefid );
191 if( isset(json_decode($briefDetail, true)['error']) && !empty( json_decode($briefDetail, true)['error'] ) ){
192 wp_send_json([
193 'success' => false,
194 'message' => 'Invalid URL, Please make sure brief is public'
195 ]);
196 }else{
197
198 ob_start();
199 include dirname(__FILE__) .'/templates/brief-detail.php';
200 $data = ob_get_clean();
201
202 wp_send_json([
203 'success' => true,
204 'html' => $data,
205 'briefid' => $briefid,
206 'briefdetailar'=> json_encode( $rcTopic )
207 ]);
208 }
209
210 }else{
211 wp_send_json([
212 'success' => false,
213 'message' => 'Invalid URL, Please make sure brief is public'
214 ]);
215 }
216 }else{
217 wp_send_json([
218 'success' => false,
219 'message' => 'Invalid URL, Please make sure brief is public'
220 ]);
221 }
222
223 }
224 }
225 wp_die();
226 }
227
228 public function brief_detail_page_back(){
229 if( current_user_can('administrator') || current_user_can('manage_options') ) {
230 include dirname(__FILE__) .'/api/usetopicapi.php';
231 $UseTopicApi = new UseTopicAPI();
232 $preloginToken = get_option('usetopicapi_token');
233 $allBriefs = $UseTopicApi->getBriefsbyTopicToken($preloginToken);
234 ob_start();
235 include dirname(__FILE__) .'/templates/briefs.php';
236 $data = ob_get_clean();
237 echo $data ;
238 }
239 wp_die();
240 }
241
242 public function brief_detail_page_grades_update(){
243 if( current_user_can('administrator') || current_user_can('manage_options') ) {
244 include dirname(__FILE__) .'/api/usetopicapi.php';
245 $UseTopicApi = new UseTopicAPI();
246
247 if(isset($_POST['briefID']) && !empty( $_POST['briefID'] ) ){
248 if( isset($_POST['byURLBF']) && $_POST['byURLBF'] == 'yes' ){
249 $briefID = $_POST['briefID'];
250 $briefContent = $_POST['content'];
251 $briefDetailUP = $UseTopicApi->getBriefUpdatedReportURL($briefID, $briefContent);
252 echo $briefDetailUP;
253
254 }else{
255 $briefID = $_POST['briefID'];
256 $briefContent = $_POST['content'];
257 $briefToken = get_option('usetopicapi_token');
258 $briefDetailUP = $UseTopicApi->getBriefUpdatedReport($briefID, $briefToken, $briefContent);
259 echo $briefDetailUP;
260 }
261
262
263 }
264 }
265 wp_die();
266 }
267 public function topic_keyword_detail_view(){
268 if( current_user_can('administrator') || current_user_can('manage_options') ) {
269 if( isset($_POST['usetopicBriefArray']) ){
270 $rcTopics = $_POST['usetopicBriefArray'];
271 $keyIndex = $_POST['indexval'];
272 $keystatus = $_POST['keystatus'];
273 ob_start();
274 include dirname(__FILE__) .'/templates/topic-keyword-detail.php';
275 $data = ob_get_clean();
276 echo $data ;
277
278 }
279 }
280 wp_die();
281 }
282 public function search_briefs_by_keyword(){
283 if( current_user_can('administrator') || current_user_can('manage_options') ) {
284 include dirname(__FILE__) .'/api/usetopicapi.php';
285 $UseTopicApi = new UseTopicAPI();
286 if( isset($_POST['search']) ){
287 $search = $_POST['search'];
288 $briefToken = get_option('usetopicapi_token');
289 $allBriefs = $UseTopicApi->getBriefsBySearch( $search, $briefToken );
290 ob_start();
291 include dirname(__FILE__) .'/templates/search.php';
292 $data = ob_get_clean();
293 echo $data ;
294
295 }
296 }
297 wp_die();
298 }
299
300
301
302 public function add_js_for_onchange_usetopic( $initArray ) {
303 $initArray['setup'] = 'function(ed){
304 ed.on("change", function(ed) {
305 updateUsetopicFrontGrades();
306 });
307 }';
308 return $initArray;
309 }
310
311 }
312
313 $wpUseTopic= new useTopicSeo();
314