| @@ -1,55 +1,51 @@ | ||
| 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.37 | |
| 10 | + */ | |
| 11 | +if( ! defined( 'ABSPATH') ) { | |
| 12 | + exit; | |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | 15 | |
| 16 | -class useTopicSeo | |
| 17 | -{ | |
| 16 | +class useTopicSeo { | |
| 18 | 17 | |
| 18 | + | |
| 19 | + public function __construct() { | |
| 20 | + global $pagenow; | |
| 21 | + if($pagenow == 'post.php' || $pagenow == 'post-new.php'){ | |
| 22 | + add_action( 'post_submitbox_misc_actions', array($this, 'add_usetopic_button_classic_editor') ); | |
| 23 | + add_action( 'admin_enqueue_scripts', array($this, 'topic_enqueue_assets_classic') ); | |
| 24 | + add_action('admin_footer', array($this, 'useTopicSeo_sidebar_box')); | |
| 25 | + add_action( 'enqueue_block_editor_assets', array($this,'topic_enqueue_assets') ); | |
| 26 | + } | |
| 27 | + add_action('wp_ajax_get_permalink_for_post_id', array($this, 'get_permalink_for_post_id')); | |
| 28 | + add_action('wp_ajax_search_posts', array($this, 'search_posts')); | |
| 29 | + } | |
| 19 | 30 | |
| 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')); | |
| 31 | + | |
| 32 | + public function add_usetopic_button_classic_editor(){ | |
| 33 | + $html = '<div id="major-publishing-actions-use-topic" style="overflow:hidden"><p>'.__( 'Topic SEO Content Optimization Tool', 'usetopic-plugin' ).'</p>'; | |
| 34 | + $html .= '<div id="publishing-action-use-topic">'; | |
| 35 | + $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>'; | |
| 36 | + $html .= '</div>'; | |
| 37 | + $html .= '</div>'; | |
| 38 | + echo $html; | |
| 31 | 39 | } |
| 32 | 40 | |
| 33 | - | |
| 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 | - } | |
| 43 | - | |
| 44 | 41 | /** |
| 45 | 42 | * Function to find the file path for index.[hash].js or index-classic.[hash].js |
| 46 | 43 | * @param string $filePattern - The file pattern to search for (e.g., 'index' or 'index-classic') |
| 47 | 44 | * @param string $directory - The directory where the build files are located |
| 48 | 45 | * @return string|null - Returns the full file path or null if not found |
| 49 | - */ | |
| 50 | - public function getHashedFilePath($filePattern, $directory = 'build') | |
| 51 | - { | |
| 46 | + */ | |
| 47 | + public function getHashedFilePath($filePattern, $directory = 'build') { | |
| 52 | 48 | // Get the full path to the plugin directory |
| 53 | 49 | $plugin_dir = plugin_dir_path(__FILE__); |
| 54 | 50 | $full_directory_path = $plugin_dir . $directory; |
| 55 | 51 | |
| @@ -74,57 +70,41 @@ | ||
| 74 | 70 | // If no match was found, return null |
| 75 | 71 | return null; |
| 76 | 72 | } |
| 77 | 73 | |
| 78 | - public function topic_enqueue_assets() | |
| 79 | - { | |
| 74 | + public function topic_enqueue_assets() { | |
| 80 | 75 | $index_file_path = $this->getHashedFilePath('index'); |
| 81 | 76 | if ($index_file_path === null) { |
| 82 | - $index_file_path = 'build/index.js'; | |
| 77 | + $index_file_path = 'build/index.js'; | |
| 83 | 78 | } |
| 84 | 79 | wp_enqueue_script( |
| 85 | 80 | 'topic-gutenberg-sidebar', |
| 86 | - plugins_url($index_file_path, __FILE__), | |
| 87 | - array('wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element'), | |
| 81 | + plugins_url( $index_file_path, __FILE__ ), | |
| 82 | + array( 'wp-plugins', 'wp-edit-post', 'wp-i18n', 'wp-element' ), | |
| 88 | 83 | null |
| 89 | 84 | ); |
| 90 | - $this->add_runtime_config('topic-gutenberg-sidebar'); | |
| 91 | - wp_enqueue_style('topic-sidebar-global', plugins_url('build/index.css', __FILE__), array(), 'all'); | |
| 85 | + wp_enqueue_style('topic-sidebar-global', plugins_url( 'build/index.css', __FILE__ ), array(), 'all'); | |
| 92 | 86 | } |
| 93 | - | |
| 94 | - public function topic_enqueue_assets_classic() | |
| 95 | - { | |
| 87 | + | |
| 88 | + public function topic_enqueue_assets_classic() { | |
| 96 | 89 | $index_file_path = $this->getHashedFilePath('index-classic'); |
| 97 | 90 | if ($index_file_path === null) { |
| 98 | - $index_file_path = 'build/index-classic.js'; | |
| 91 | + $index_file_path = 'build/index-classic.js'; | |
| 99 | 92 | } |
| 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'); | |
| 93 | + wp_enqueue_script( | |
| 94 | + 'topic-gutenberg-sidebar-classic', | |
| 95 | + plugins_url( $index_file_path , __FILE__ ), array('wp-plugins'), null | |
| 96 | + ); | |
| 97 | + wp_enqueue_style('topic-classic-sidebar', plugins_url( 'classic-editor/classic.css', __FILE__ ), array(), 'all'); | |
| 98 | + wp_enqueue_style('topic-sidebar-global', plugins_url( 'build/index.css', __FILE__ ), array(), 'all'); | |
| 109 | 99 | } |
| 110 | - | |
| 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'); | |
| 100 | + | |
| 101 | + public function useTopicSeo_sidebar_box($data) { | |
| 102 | + 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>'; | |
| 117 | 103 | } |
| 118 | 104 | |
| 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 | - } | |
| 123 | - | |
| 124 | - public function get_permalink_for_post_id() | |
| 125 | - { | |
| 126 | - if (isset($_POST['post_id'])) { | |
| 105 | + public function get_permalink_for_post_id(){ | |
| 106 | + if(isset($_POST['post_id'])){ | |
| 127 | 107 | $post_id = $_POST['post_id']; |
| 128 | 108 | $permalink = get_permalink(intval($post_id)); |
| 129 | 109 | |
| 130 | 110 | wp_send_json([ |
| @@ -133,22 +113,22 @@ | ||
| 133 | 113 | } |
| 134 | 114 | wp_die(); |
| 135 | 115 | } |
| 136 | 116 | |
| 137 | - public function search_posts() | |
| 138 | - { | |
| 139 | - if (isset($_POST['s'])) { | |
| 117 | + public function search_posts(){ | |
| 118 | + if(isset($_POST['s'])){ | |
| 140 | 119 | $s = $_POST['s']; |
| 141 | 120 | |
| 142 | 121 | 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) . '%')); | |
| 122 | + $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 | 123 | $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); | |
| 124 | + foreach ( $myposts as $mypost ) | |
| 125 | + { | |
| 126 | + // $post = get_post($mypost); | |
| 127 | + $permalink = get_permalink(intval($mypost->ID)); | |
| 128 | + $mypost->permalink = $permalink; | |
| 129 | + $mypost->post_content = ""; | |
| 130 | + array_push($post_array, $mypost); | |
| 151 | 131 | } |
| 152 | 132 | |
| 153 | 133 | wp_send_json([ |
| 154 | 134 | 'posts' => $post_array |
| @@ -158,6 +138,6 @@ | ||
| 158 | 138 | } |
| 159 | 139 | |
| 160 | 140 | |
| 161 | 141 | } |
| 162 | - | |
| 163 | -$wpUseTopic = new useTopicSeo(); | |
| 142 | + | |
| 143 | +$wpUseTopic= new useTopicSeo(); | |