PluginProbe
Topic SEO Content Optimization Tool / 1.0.40
Topic SEO Content Optimization Tool v1.0.40
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 +116 -263 1.0.101.0.40 View file →
@@ -1,300 +1,153 @@
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.10
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.40
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' );
23 15
24 -class useTopicSeo {
16 +class useTopicSeo
17 +{
25 18
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') );
19 +
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'));
30 26 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'));
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'));
31 + }
32 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 33
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;
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;
51 42 }
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 43
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;
70 55
71 - $preloginToken = get_option('usetopicapi_token');
72 - if(!empty($preloginToken)){
73 - $allBriefs = $UseTopicApi->getBriefsbyTopicToken($preloginToken);
74 - if(is_object( json_decode( $allBriefs ) )){
56 + if (!is_dir($full_directory_path)) {
57 + return null;
58 + }
75 59
76 - ob_start();
77 - include dirname(__FILE__) .'/templates/briefs.php';
78 - $data = ob_get_clean();
79 - echo $data ;
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, '/'));
80 62
81 - }else{
63 + // Scan the directory for files
64 + $files = scandir($full_directory_path);
82 65
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();
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;
92 71 }
72 + }
93 73
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 - ]);
74 + // If no match was found, return null
75 + return null;
76 + }
102 77
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();
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';
83 + }
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 + wp_enqueue_style('topic-sidebar-global', plugins_url('build/index.css', __FILE__), array(), 'all');
136 91 }
137 92
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 -
93 + public function topic_enqueue_assets_classic()
94 + {
95 + $index_file_path = $this->getHashedFilePath('index-classic');
96 + if ($index_file_path === null) {
97 + $index_file_path = 'build/index-classic.js';
147 98 }
148 - wp_die();
99 + wp_enqueue_script(
100 + 'topic-gutenberg-sidebar-classic',
101 + plugins_url($index_file_path, __FILE__),
102 + array('wp-plugins'),
103 + null
104 + );
105 + wp_enqueue_style('topic-classic-sidebar', plugins_url('classic-editor/classic.css', __FILE__), array(), 'all');
106 + wp_enqueue_style('topic-sidebar-global', plugins_url('build/index.css', __FILE__), array(), 'all');
149 107 }
150 - public function brief_detail_page(){
151 - include dirname(__FILE__) .'/api/usetopicapi.php';
152 - $UseTopicApi = new UseTopicAPI();
153 108
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();
109 + public function useTopicSeo_sidebar_box($data)
110 + {
111 + 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>';
220 112 }
221 113
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 ;
114 + public function get_permalink_for_post_id()
115 + {
116 + if (isset($_POST['post_id'])) {
117 + $post_id = $_POST['post_id'];
118 + $permalink = get_permalink(intval($post_id));
231 119
120 + wp_send_json([
121 + 'permalink' => $permalink
122 + ]);
123 + }
232 124 wp_die();
233 125 }
234 126
235 - public function brief_detail_page_grades_update(){
236 - include dirname(__FILE__) .'/api/usetopicapi.php';
237 - $UseTopicApi = new UseTopicAPI();
127 + public function search_posts()
128 + {
129 + if (isset($_POST['s'])) {
130 + $s = $_POST['s'];
238 131
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 -
132 + global $wpdb;
133 + $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) . '%'));
134 + $post_array = array();
135 + foreach ($myposts as $mypost) {
136 + // $post = get_post($mypost);
137 + $permalink = get_permalink(intval($mypost->ID));
138 + $mypost->permalink = $permalink;
139 + $mypost->post_content = "";
140 + array_push($post_array, $mypost);
255 141 }
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 142
268 - }
143 + wp_send_json([
144 + 'posts' => $post_array
145 + ]);
146 + }
269 147 wp_die();
270 148 }
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 149
283 - }
284 - wp_die();
285 - }
286 150
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 - }
151 +}
297 152
298 -}
299 -
300 -$wpUseTopic= new useTopicSeo();
153 +$wpUseTopic = new useTopicSeo();