PluginProbe
Topic SEO Content Optimization Tool / 1.0.8
Topic SEO Content Optimization Tool v1.0.8
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
← All changes | index.php +272 -122 trunk1.0.8 View file →
@@ -1,163 +1,313 @@
1 1 <?php
2 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.43
10 - */
11 -if (!defined('ABSPATH')) {
12 - exit;
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.8
10 + */
11 +if( ! defined( 'ABSPATH') ) {
12 + exit;
13 13 }
14 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' );
15 23
16 -class useTopicSeo
17 -{
24 +class useTopicSeo {
18 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'));
19 32
20 - public function __construct()
21 - {
22 - global $pagenow;
23 - if ($pagenow == 'post.php' || $pagenow == 'post-new.php') {
24 - add_action('post_submitbox_misc_actions', array($this, 'add_usetopic_button_classic_editor'));
25 - add_action('admin_enqueue_scripts', array($this, 'topic_enqueue_assets_classic'));
26 - add_action('admin_footer', array($this, 'useTopicSeo_sidebar_box'));
27 - add_action('enqueue_block_editor_assets', array($this, 'topic_enqueue_assets'));
28 - }
29 - add_action('wp_ajax_get_permalink_for_post_id', array($this, 'get_permalink_for_post_id'));
30 - add_action('wp_ajax_search_posts', array($this, 'search_posts'));
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;
31 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();
32 70
33 71
34 - public function add_usetopic_button_classic_editor()
35 - {
36 - $html = '<div id="major-publishing-actions-use-topic" style="overflow:hidden"><p>' . __('Topic SEO Content Optimization Tool', 'usetopic-plugin') . '</p>';
37 - $html .= '<div id="publishing-action-use-topic">';
38 - $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>';
39 - $html .= '</div>';
40 - $html .= '</div>';
41 - echo $html;
42 - }
72 + $preloginToken = get_option('usetopicapi_token');
73 + if(!empty($preloginToken)){
74 + $allBriefs = $UseTopicApi->getBriefsbyTopicToken($preloginToken);
75 + if(is_object( json_decode( $allBriefs ) )){
43 76
44 - /**
45 - * Function to find the file path for index.[hash].js or index-classic.[hash].js
46 - * @param string $filePattern - The file pattern to search for (e.g., 'index' or 'index-classic')
47 - * @param string $directory - The directory where the build files are located
48 - * @return string|null - Returns the full file path or null if not found
49 - */
50 - public function getHashedFilePath($filePattern, $directory = 'build')
51 - {
52 - // Get the full path to the plugin directory
53 - $plugin_dir = plugin_dir_path(__FILE__);
54 - $full_directory_path = $plugin_dir . $directory;
77 + ob_start();
78 + include dirname(__FILE__) .'/templates/briefs.php';
79 + $data = ob_get_clean();
80 + echo $data ;
55 81
56 - if (!is_dir($full_directory_path)) {
57 - return null;
58 - }
82 + }else{
59 83
60 - // Define the regex pattern to match files like index.[hash].js or index-classic.[hash].js
61 - $pattern = sprintf('/^%s\.[a-f0-9]{8}\.js$/', preg_quote($filePattern, '/'));
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 ;
62 90
63 - // Scan the directory for files
64 - $files = scandir($full_directory_path);
91 + }
92 + wp_die();
93 + }
65 94
66 - // Iterate through the files to find a match
67 - foreach ($files as $file) {
68 - if (preg_match($pattern, $file)) {
69 - // Return the relative path of the matched file
70 - return $directory . '/' . $file;
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 ;
71 134 }
135 +
136 + die();
72 137 }
138 + }
73 139
74 - // If no match was found, return null
75 - return null;
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 + }
76 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();
77 158
78 - public function topic_enqueue_assets()
79 - {
80 - $index_file_path = $this->getHashedFilePath('index');
81 - if ($index_file_path === null) {
82 - $index_file_path = 'build/index.js';
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 + }
83 224 }
84 - wp_enqueue_script(
85 - 'topic-gutenberg-sidebar',
86 - plugins_url($index_file_path, __FILE__),
87 - array('wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element'),
88 - null
89 - );
90 - $this->add_runtime_config('topic-gutenberg-sidebar');
91 - wp_enqueue_style('topic-sidebar-global', plugins_url('build/index.css', __FILE__), array(), 'all');
225 + wp_die();
92 226 }
93 227
94 - public function topic_enqueue_assets_classic()
95 - {
96 - $index_file_path = $this->getHashedFilePath('index-classic');
97 - if ($index_file_path === null) {
98 - $index_file_path = 'build/index-classic.js';
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 ;
99 238 }
100 - wp_enqueue_script(
101 - 'topic-gutenberg-sidebar-classic',
102 - plugins_url($index_file_path, __FILE__),
103 - array('wp-plugins'),
104 - null
105 - );
106 - $this->add_runtime_config('topic-gutenberg-sidebar-classic');
107 - wp_enqueue_style('topic-classic-sidebar', plugins_url('classic-editor/classic.css', __FILE__), array(), 'all');
108 - wp_enqueue_style('topic-sidebar-global', plugins_url('build/index.css', __FILE__), array(), 'all');
239 + wp_die();
109 240 }
110 241
111 - private function add_runtime_config($handle)
112 - {
113 - $config = array(
114 - 'disableTelemetry' => getenv('TOPIC_DISABLE_TELEMETRY') === '1'
115 - );
116 - wp_add_inline_script($handle, 'window.topicPluginConfig = ' . wp_json_encode($config) . ';', 'before');
117 - }
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();
118 246
119 - public function useTopicSeo_sidebar_box($data)
120 - {
121 - 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>';
122 - }
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;
123 253
124 - public function get_permalink_for_post_id()
125 - {
126 - if (isset($_POST['post_id'])) {
127 - $post_id = $_POST['post_id'];
128 - $permalink = get_permalink(intval($post_id));
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 +
129 262
130 - wp_send_json([
131 - 'permalink' => $permalink
132 - ]);
263 + }
133 264 }
134 265 wp_die();
135 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 ;
136 277
137 - public function search_posts()
138 - {
139 - if (isset($_POST['s'])) {
140 - $s = $_POST['s'];
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 ;
141 294
142 - global $wpdb;
143 - $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) . '%'));
144 - $post_array = array();
145 - foreach ($myposts as $mypost) {
146 - // $post = get_post($mypost);
147 - $permalink = get_permalink(intval($mypost->ID));
148 - $mypost->permalink = $permalink;
149 - $mypost->post_content = "";
150 - array_push($post_array, $mypost);
151 295 }
152 -
153 - wp_send_json([
154 - 'posts' => $post_array
155 - ]);
156 296 }
157 297 wp_die();
158 298 }
159 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 + }
160 310
161 311 }
162 -
163 -$wpUseTopic = new useTopicSeo();
312 +
313 +$wpUseTopic= new useTopicSeo();