Plugin Directory

Changeset 2720242


Ignore:
Timestamp:
05/08/2022 07:11:38 PM (4 years ago)
Author:
vladimir.s
Message:

Terms descriptions v.3.4.1. [terms-descriptions] shortcode added, convert in archive descriptions option added, support of t_use_in_post_types column added to packet upload and export to CSV, support of t_use_in_post_types column added to export and import, PHPUnit 9.5 support, www. subdomain removed from SERVER_NAME in is_current_url function, WordPress 5.9.3 support

Location:
terms-descriptions/trunk
Files:
5 added
3 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • terms-descriptions/trunk/includes/parsers/td_parser.php

    r2252681 r2720242  
    162162            return $this->cur_url;
    163163        }
     164
     165        $server_name = preg_replace('/^www\./i', '', $_SERVER[ "SERVER_NAME" ]);
     166
    164167        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" ] );
    166169        } else {
    167             $this->cur_url = trailingslashit( $_SERVER[ "SERVER_NAME" ] . $_SERVER[ "REQUEST_URI" ] );
     170            $this->cur_url = trailingslashit( $server_name . $_SERVER[ "REQUEST_URI" ] );
    168171        }
    169172        return $this->cur_url;
  • terms-descriptions/trunk/includes/td_admin_options.php

    r2310710 r2720242  
    137137                </tr>
    138138                <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">
    139146                    <th scope="row"><?php _e( 'Open link in a new tab', 'terms-descriptions' ); ?></th>
    140147                    <td>
     
    254261            $input[ 'convert_only_single' ] = false;
    255262        }
     263        if ( !isset( $input[ 'convert_archive_descriptions' ] ) ) {
     264            $input[ 'convert_archive_descriptions' ] = false;
     265        }
    256266        if ( !isset( $input[ 'open_new_tab' ] ) ) {
    257267            $input[ 'open_new_tab' ] = false;
  • terms-descriptions/trunk/includes/td_admin_tools.php

    r2252681 r2720242  
    9090        <label><?php _e( 'Terms list', 'terms-descriptions' ); ?> <textarea name="terms" rows="10" cols="40" class="large-text code"></textarea></label>
    9191        <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)'
    9393                .'<br />Examples:'
    9494                .'<br />apple|apples|21'
    95                 .'<br />pear|pears|http://site.domen<br />'
     95                .'<br />pear|pears|http://site.domen|post,page,attachment<br />'
    9696                .'Note that if you use term_id the post with this id should exist.', 'terms-descriptions' ); ?></div>
    9797        <input type="submit" name="td_packet_upload" value="<?php _e( 'Add terms', 'terms-descriptions' ); ?>" class="button-primary" />
     
    121121        $data = array();
    122122        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 );
    124129        }
    125130       
     
    147152                global $wpdb;
    148153                //saving terms
    149                 $insert_sql = 'INSERT INTO ' . $wpdb->prefix . 'td_terms VALUES (null,%d,%s,%s,%s,%s)';
    150154                foreach ( $data as $term ) {
    151155                    if ( isset( $term->t_post_id ) && isset( $term->t_post_title )
    152156                            && isset( $term->t_post_url ) && isset( $term->t_post_type )
    153157                            && 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
    155166                                , $term->t_post_url, $term->t_post_type, $term->t_term ) );
     167                        }
    156168                    }
    157169                }
     
    194206                continue;
    195207            }
    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
    197225            $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
    202234            //checking terms links
    203235            if ( false !== ( $link_data = $this->check_link( $link ) ) ) {
    204236                $term_data = array_merge( $link_data, $term_data );
    205                
     237
    206238                //saving term
    207239                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
    209247                if ( !is_int( $wpdb->insert_id ) || ( int )$wpdb->insert_id <= 0 ) {
    210248                    return false;
     
    232270                $term = $termRow->t_term;
    233271                $link = $termRow->t_post_url;
     272                $row = '"' . $link . '";';
    234273                if ( false !== strpos( $term, '|' ) ) {
    235274                    $termsArr = explode( '|', $term );
     
    237276                        $termsArr[$i] = '"' . iconv( 'UTF-8', 'windows-1251', str_replace( '"', '""', trim( stripslashes( $value ) ) ) ) . '"';
    238277                    }
    239                     $list[] = '"' . $link . '";' . implode( ';', $termsArr );
     278                    $row .= implode( ';', $termsArr );
    240279                }
    241280                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;
    244292            }
    245293        }
  • terms-descriptions/trunk/includes/td_frontend.php

    r2694981 r2720242  
    2222            add_filter( 'comment_text', array( $this, 'parse_content' ) );
    2323        }
     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        });
    2432    }
    2533
     
    3139     * @return string updated post content
    3240     */
    33     public function parse_content( $content ) {
     41    public function parse_content( $content, $is_td_shortcode = false ) {
    3442        //checking if have to convert terms on this page
    3543        if ( false === $this->options->getOption( 'convert_only_single' ) || is_single() || is_page() ) {
    3644            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 ) ) {
    3846                return $content;
    3947            }
  • terms-descriptions/trunk/readme.txt

    r2694981 r2720242  
    33Tags: post, page, links, plugin, link building, cross linking, seo
    44Requires at least: 4.1
    5 Tested up to: 5.9.2
     5Tested up to: 5.9.3
    66Stable tag: trunk
    77
     
    7979== Changelog ==
    8080
     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
    8191= 3.4.0 =
    8292
  • terms-descriptions/trunk/terms-descriptions.php

    r2694981 r2720242  
    44Plugin URI: https://simplecoding.org/plagin-wordpress-terms-descriptions
    55Description: 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.0
     6Version: 3.4.1
    77Author: Vladimir Statsenko
    88Author URI: https://simplecoding.org
  • terms-descriptions/trunk/tests/mockpress/test/CommentsTest.php

    r928266 r2720242  
    44require_once(dirname(__FILE__) . '/../includes/comments.php');
    55
    6 class CommentsTest extends PHPUnit_Framework_TestCase {
    7     function setUp() {
     6class CommentsTest extends \PHPUnit\Framework\TestCase {
     7    protected function setUp(): void {
    88        _reset_wp();
    99        $_SERVER = array();
  • terms-descriptions/trunk/tests/mockpress/test/MockPressTest.php

    r928266 r2720242  
    44require_once(dirname(__FILE__) . '/../mockpress.php');
    55
    6 class MockPressTest extends PHPUnit_Framework_TestCase {
    7     function setUp() {
     6class MockPressTest extends \PHPUnit\Framework\TestCase {
     7    protected function setUp(): void {
    88        global $post;
    99        _reset_wp();
Note: See TracChangeset for help on using the changeset viewer.