Changeset 2720242
- Timestamp:
- 05/08/2022 07:11:38 PM (4 years ago)
- Location:
- terms-descriptions/trunk
- Files:
-
- 5 added
- 3 deleted
- 8 edited
-
includes/parsers/td_parser.php (modified) (1 diff)
-
includes/td_admin_options.php (modified) (2 diffs)
-
includes/td_admin_tools.php (modified) (6 diffs)
-
includes/td_frontend.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
terms-descriptions.php (modified) (1 diff)
-
tests/TDLongTermsFirstTest.php (deleted)
-
tests/TDSimpleParserTest.php (deleted)
-
tests/TDSimpleQuotesParserTest.php (deleted)
-
tests/mockpress/test/CommentsTest.php (modified) (1 diff)
-
tests/mockpress/test/MockPressTest.php (modified) (1 diff)
-
tests/tests (added)
-
tests/tests/TDLongTermsFirstTest.php (added)
-
tests/tests/TDSimpleParserTest.php (added)
-
tests/tests/TDSimpleQuotesParserTest.php (added)
-
tests/tests/phpunit.xml (added)
Legend:
- Unmodified
- Added
- Removed
-
terms-descriptions/trunk/includes/parsers/td_parser.php
r2252681 r2720242 162 162 return $this->cur_url; 163 163 } 164 165 $server_name = preg_replace('/^www\./i', '', $_SERVER[ "SERVER_NAME" ]); 166 164 167 if ( !in_array( $_SERVER[ "SERVER_PORT" ], array( "80", "443" ) ) ) { 165 $this->cur_url = trailingslashit( $ _SERVER[ "SERVER_NAME" ]. ":" . $_SERVER[ "SERVER_PORT" ] . $_SERVER[ "REQUEST_URI" ] );168 $this->cur_url = trailingslashit( $server_name . ":" . $_SERVER[ "SERVER_PORT" ] . $_SERVER[ "REQUEST_URI" ] ); 166 169 } else { 167 $this->cur_url = trailingslashit( $ _SERVER[ "SERVER_NAME" ]. $_SERVER[ "REQUEST_URI" ] );170 $this->cur_url = trailingslashit( $server_name . $_SERVER[ "REQUEST_URI" ] ); 168 171 } 169 172 return $this->cur_url; -
terms-descriptions/trunk/includes/td_admin_options.php
r2310710 r2720242 137 137 </tr> 138 138 <tr valign="middle"> 139 <th scope="row"><?php _e( 'Convert terms in archive descriptions', 'terms-descriptions' ); ?></th> 140 <td> 141 <input name="td_options[convert_archive_descriptions]" type="checkbox" id="convert_archive_descriptions" <?php if ( isset( $options[ 'convert_archive_descriptions' ] ) ) { checked( $options[ 'convert_archive_descriptions' ], 'on' ); } ?> /> 142 <span class="description"><?php _e( 'Terms will be converted convert in archive descriptions.', 'terms-descriptions' ); ?></span> 143 </td> 144 </tr> 145 <tr valign="middle"> 139 146 <th scope="row"><?php _e( 'Open link in a new tab', 'terms-descriptions' ); ?></th> 140 147 <td> … … 254 261 $input[ 'convert_only_single' ] = false; 255 262 } 263 if ( !isset( $input[ 'convert_archive_descriptions' ] ) ) { 264 $input[ 'convert_archive_descriptions' ] = false; 265 } 256 266 if ( !isset( $input[ 'open_new_tab' ] ) ) { 257 267 $input[ 'open_new_tab' ] = false; -
terms-descriptions/trunk/includes/td_admin_tools.php
r2252681 r2720242 90 90 <label><?php _e( 'Terms list', 'terms-descriptions' ); ?> <textarea name="terms" rows="10" cols="40" class="large-text code"></textarea></label> 91 91 <div class="description"><?php _e( 'Each term should be written on its own line. Use the following format.' 92 .'<br />word_form_1|word_form_2|...|post_id OR URL (with http://) '92 .'<br />word_form_1|word_form_2|...|post_id OR URL (with http://)|post_types (delimited with comma)' 93 93 .'<br />Examples:' 94 94 .'<br />apple|apples|21' 95 .'<br />pear|pears|http://site.domen <br />'95 .'<br />pear|pears|http://site.domen|post,page,attachment<br />' 96 96 .'Note that if you use term_id the post with this id should exist.', 'terms-descriptions' ); ?></div> 97 97 <input type="submit" name="td_packet_upload" value="<?php _e( 'Add terms', 'terms-descriptions' ); ?>" class="button-primary" /> … … 121 121 $data = array(); 122 122 if ( is_array( $terms ) && !empty( $terms ) ) { 123 $data = json_encode($terms); 123 foreach ( $terms as $key => $term ) { 124 if ( isset( $term->t_use_in_post_types ) && !empty( $term->t_use_in_post_types ) ) { 125 $terms[ $key ]->t_use_in_post_types = unserialize( $term->t_use_in_post_types ); 126 } 127 } 128 $data = json_encode( $terms, JSON_UNESCAPED_UNICODE ); 124 129 } 125 130 … … 147 152 global $wpdb; 148 153 //saving terms 149 $insert_sql = 'INSERT INTO ' . $wpdb->prefix . 'td_terms VALUES (null,%d,%s,%s,%s,%s)';150 154 foreach ( $data as $term ) { 151 155 if ( isset( $term->t_post_id ) && isset( $term->t_post_title ) 152 156 && isset( $term->t_post_url ) && isset( $term->t_post_type ) 153 157 && isset( $term->t_term ) ) { 154 $wpdb->query( $wpdb->prepare( $insert_sql, $term->t_post_id, $term->t_post_title 158 if ( isset( $term->t_use_in_post_types ) ) { 159 $insert_sql = 'INSERT INTO ' . $wpdb->prefix . 'td_terms VALUES (null,%d,%s,%s,%s,%s,%s)'; 160 $t_use_in_post_types = serialize( $term->t_use_in_post_types ); 161 $wpdb->query( $wpdb->prepare( $insert_sql, $term->t_post_id, $term->t_post_title 162 , $term->t_post_url, $term->t_post_type, $term->t_term, $t_use_in_post_types ) ); 163 } else { 164 $insert_sql = 'INSERT INTO ' . $wpdb->prefix . 'td_terms VALUES (null,%d,%s,%s,%s,%s,null)'; 165 $wpdb->query( $wpdb->prepare( $insert_sql, $term->t_post_id, $term->t_post_title 155 166 , $term->t_post_url, $term->t_post_type, $term->t_term ) ); 167 } 156 168 } 157 169 } … … 194 206 continue; 195 207 } 196 208 209 $hasUsedInPostTypes = false; 210 $usedInPostTypes = null; 211 if ( count( $term_parts ) >= 3 ) { 212 $postTypes = get_post_types( array( 213 'public' => true, 214 'show_ui' => true, 215 ), 'objects' ); 216 $usedInPostTypes = explode(',', $term_parts[ count( $term_parts ) - 1 ] ); 217 foreach ( $postTypes as $typeName => $type ) { 218 if ( in_array( $typeName, $usedInPostTypes ) ) { 219 $hasUsedInPostTypes = true; 220 break; 221 } 222 } 223 } 224 197 225 $term_data = array(); 198 $term_data[ 't_term' ] = implode( '|', array_slice( $term_parts, 0, count( $term_parts ) - 1 ) ); 199 200 $link = $term_parts[ count( $term_parts ) - 1 ]; 201 226 if ( true === $hasUsedInPostTypes ) { 227 $term_data[ 't_term' ] = implode( '|', array_slice( $term_parts, 0, count( $term_parts ) - 2 ) ); 228 $link = $term_parts[ count( $term_parts ) - 2 ]; 229 } else { 230 $term_data[ 't_term' ] = implode( '|', array_slice( $term_parts, 0, count( $term_parts ) - 1 ) ); 231 $link = $term_parts[ count( $term_parts ) - 1 ]; 232 } 233 202 234 //checking terms links 203 235 if ( false !== ( $link_data = $this->check_link( $link ) ) ) { 204 236 $term_data = array_merge( $link_data, $term_data ); 205 237 206 238 //saving term 207 239 global $wpdb; 208 $wpdb->insert( $wpdb->prefix . 'td_terms', $term_data, array( '%d', '%s', '%s', '%s', '%s' ) ); 240 if ( true === $hasUsedInPostTypes && is_array( $usedInPostTypes ) && !empty( $usedInPostTypes ) ) { 241 $term_data[ 't_use_in_post_types' ] = serialize( $usedInPostTypes ); 242 $wpdb->insert( $wpdb->prefix . 'td_terms', $term_data, array( '%d', '%s', '%s', '%s', '%s', '%s' ) ); 243 } else { 244 $wpdb->insert( $wpdb->prefix . 'td_terms', $term_data, array( '%d', '%s', '%s', '%s', '%s' ) ); 245 } 246 209 247 if ( !is_int( $wpdb->insert_id ) || ( int )$wpdb->insert_id <= 0 ) { 210 248 return false; … … 232 270 $term = $termRow->t_term; 233 271 $link = $termRow->t_post_url; 272 $row = '"' . $link . '";'; 234 273 if ( false !== strpos( $term, '|' ) ) { 235 274 $termsArr = explode( '|', $term ); … … 237 276 $termsArr[$i] = '"' . iconv( 'UTF-8', 'windows-1251', str_replace( '"', '""', trim( stripslashes( $value ) ) ) ) . '"'; 238 277 } 239 $ list[] = '"' . $link . '";' .implode( ';', $termsArr );278 $row .= implode( ';', $termsArr ); 240 279 } 241 280 else { 242 $list[] = '"' . $link . '";' . '"' . iconv( 'UTF-8', 'windows-1251', str_replace( '"', '""', trim( stripslashes( $term ) ) ) ) . '"'; 243 } 281 $row .= '"' . iconv( 'UTF-8', 'windows-1251', str_replace( '"', '""', trim( stripslashes( $term ) ) ) ) . '"'; 282 } 283 284 if (!empty($termRow->t_use_in_post_types)) { 285 $usedInPostTypes = unserialize( $termRow->t_use_in_post_types ); 286 if (is_array($usedInPostTypes)) { 287 $row .= ';"' . implode( ',', $usedInPostTypes). '"'; 288 } 289 } 290 291 $list[] = $row; 244 292 } 245 293 } -
terms-descriptions/trunk/includes/td_frontend.php
r2694981 r2720242 22 22 add_filter( 'comment_text', array( $this, 'parse_content' ) ); 23 23 } 24 //convert in archive descriptions 25 if ( 'on' === $this->options->getOption( 'convert_archive_descriptions' ) ) { 26 add_filter( 'get_the_archive_description', array( $this, 'parse_content' ) ); 27 } 28 29 add_shortcode('terms-descriptions', function ( $atts, $content = "" ) { 30 return $this->parse_content( $content, true ); 31 }); 24 32 } 25 33 … … 31 39 * @return string updated post content 32 40 */ 33 public function parse_content( $content ) {41 public function parse_content( $content, $is_td_shortcode = false ) { 34 42 //checking if have to convert terms on this page 35 43 if ( false === $this->options->getOption( 'convert_only_single' ) || is_single() || is_page() ) { 36 44 global $wpdb, $post; 37 if ( 'on' === get_post_meta( $post->ID, '_disable_terms_descriptions', true ) ) {45 if ( false === $is_td_shortcode && 'on' === get_post_meta( $post->ID, '_disable_terms_descriptions', true ) ) { 38 46 return $content; 39 47 } -
terms-descriptions/trunk/readme.txt
r2694981 r2720242 3 3 Tags: post, page, links, plugin, link building, cross linking, seo 4 4 Requires at least: 4.1 5 Tested up to: 5.9. 25 Tested up to: 5.9.3 6 6 Stable tag: trunk 7 7 … … 79 79 == Changelog == 80 80 81 = 3.4.1 = 82 83 * New feature: [terms-descriptions] shortcode added 84 * New feature: convert in archive descriptions option added 85 * New feature: support of t_use_in_post_types column added to packet upload and export to CSV 86 * New feature: support of t_use_in_post_types column added to export and import 87 * Improvement: PHPUnit 9.5 support 88 * Bug fix: "www." subdomain removed from SERVER_NAME in is_current_url function 89 * WordPress 5.9.3 support 90 81 91 = 3.4.0 = 82 92 -
terms-descriptions/trunk/terms-descriptions.php
r2694981 r2720242 4 4 Plugin URI: https://simplecoding.org/plagin-wordpress-terms-descriptions 5 5 Description: This plugin allows you to create list of terms and assign links to them. Plugin automatically replaces terms occurrences in your posts with appropriate links. You can control the number of replacements. After activation you can create terms list on plugin administration page (Tools -> Terms Descriptions). 6 Version: 3.4. 06 Version: 3.4.1 7 7 Author: Vladimir Statsenko 8 8 Author URI: https://simplecoding.org -
terms-descriptions/trunk/tests/mockpress/test/CommentsTest.php
r928266 r2720242 4 4 require_once(dirname(__FILE__) . '/../includes/comments.php'); 5 5 6 class CommentsTest extends PHPUnit_Framework_TestCase {7 function setUp(){6 class CommentsTest extends \PHPUnit\Framework\TestCase { 7 protected function setUp(): void { 8 8 _reset_wp(); 9 9 $_SERVER = array(); -
terms-descriptions/trunk/tests/mockpress/test/MockPressTest.php
r928266 r2720242 4 4 require_once(dirname(__FILE__) . '/../mockpress.php'); 5 5 6 class MockPressTest extends PHPUnit_Framework_TestCase {7 function setUp(){6 class MockPressTest extends \PHPUnit\Framework\TestCase { 7 protected function setUp(): void { 8 8 global $post; 9 9 _reset_wp();
Note: See TracChangeset
for help on using the changeset viewer.