Plugin Directory

Changeset 841255


Ignore:
Timestamp:
01/19/2014 11:38:49 AM (12 years ago)
Author:
SivaDu
Message:

to version 0.1.6
fixed bugs which can cause 404 error

Location:
anylink/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • anylink/trunk/anyLink.php

    r836042 r841255  
    44Plugin URI: http://dudo.org/anylink
    55Description: anyLink is an external links management tool. It help you to covert all the external links in your posts into internal links automatically. It can prevent the website weight flow outside to others. It's absolutely SEO friendly.
    6 Version: 0.1.5
     6Version: 0.1.6
    77Author: dudo
    88Author URI: http://dudo.org/about
     
    1414require_once( ANYLNK_PATH . '/classes/al_filter.php' );
    1515require_once( ANYLNK_PATH . '/classes/al_slug.php' );
    16 require_once( 'functions.php' );
     16require_once( ANYLNK_PATH . '/functions.php' );
    1717require_once( ANYLNK_PATH . '/classes/al_option.php' );
    18 register_activation_hook( __FILE__, 'anylnkInstall' );
     18
    1919$filter = new al_filter();
    2020$alOption = new al_option();
     21
     22register_activation_hook( __FILE__, 'anylnkInstall' );
    2123add_action( 'transition_post_status', 'post_published', 10, 3 );
    2224add_action( 'wp_loaded','checkFlush' );
     25add_filter( 'query_vars', array( $filter, 'addQueryVars' ) );
     26add_action( 'parse_request', array( &$filter, 'alter_the_query' ) );
     27add_action( 'plugins_loaded', 'al_load_textdomain' );
     28add_filter( 'the_content', 'filterByType' );
     29add_filter( 'rewrite_rules_array','anylink_rewrite_rules' );
    2330
    2431/**
     
    3037 * @since version 0.1.5
    3138 */
    32 function checkFlush(){
     39function checkFlush() {
    3340    $rules = get_option( 'rewrite_rules' );
    3441    $alOption = get_option( 'anylink_options' );
    3542    $cat = $alOption['redirectCat'];
    36    
    37     if( ! isset( $rules[$cat . '/([0-9a-z]{4,})'] ) ){
     43    if( ! isset( $rules[$cat . '/([0-9a-z]{4,})/?$'] ) ){
    3844        global $wp_rewrite;
    3945        $wp_rewrite -> flush_rules();
    4046    }
    4147}
     48
     49//add rewrite rules
     50function anylink_rewrite_rules( $rules ) {
     51    $alOption = get_option( 'anylink_options' );
     52    $cat = $alOption['redirectCat'];
     53    $newrules = array();
     54    $newrules[$cat . '/([0-9a-z]{4,})/?$'] = 'index.php?' . $cat . '=$matches[1]';
     55    return $newrules + $rules;
     56}
     57
    4258/**
    4359 * This function is to replace old ACTTION hook 'publish_post'
     
    5874    }
    5975}
    60 
    61 add_filter( 'the_content', 'filterByType' );
    6276
    6377/**
     
    88102    }
    89103}
    90 
    91 add_filter('query_vars', array( &$filter, 'addQueryVars' ) );
    92 add_action( 'parse_request', array( &$filter, 'alter_the_query' ) );
    93 add_action( 'plugins_loaded', 'al_load_textdomain' );
    94104?>
  • anylink/trunk/classes/al_filter.php

    r836042 r841255  
    5757    }
    5858    public function addQueryVars( $qvars ) {
    59         $qvars[] = $this -> redirectCat;
     59        array_push( $qvars, $this -> redirectCat );
    6060        return $qvars;
    6161    }
  • anylink/trunk/classes/al_option.php

    r834848 r841255  
    145145                $redirectFile = substr( plugins_url(), strlen( home_url() ) + 1 ) . '/' . ANYLNK_PLUGIN . '/redirect.php';
    146146                /* add an external rewrite rule which will  be written into .htaccess file */
    147                 $wp_rewrite -> add_external_rule( "$cat/([0-9a-z]{4,})",  $redirectFile . '?slug=$1' );
     147                $wp_rewrite -> add_external_rule( "$cat/([0-9a-z]{4,})/?$",  $redirectFile . '?slug=$1' );
    148148                flush_rewrite_rules();
    149149            } else {
    150150                $wp_rewrite -> flush_rules( true );
    151                 add_rewrite_rule( "$cat/([0-9a-z]{4,})", 'index.php?' . $cat . '=$matches[1]', 'top' );
     151                add_rewrite_rule( "$cat/([0-9a-z]{4,})/?$", 'index.php?' . $cat . '=$matches[1]', 'top' );
    152152                flush_rewrite_rules();
    153153            }
  • anylink/trunk/functions.php

    r836042 r841255  
    11<?php
    22defined( 'ABSPATH' ) OR exit;
     3if(!function_exists('_log')){
     4  function _log( $str = '', $message ) {
     5    if( WP_DEBUG === true ){
     6      if( is_array( $message ) || is_object( $message ) ){
     7        error_log( $str );
     8        error_log( print_r( $message, true ) );
     9      } else {
     10        error_log( $str );
     11        error_log( $message );
     12      }
     13    }
     14  }
     15}
    316function indexOf( $substr, $str ) {
    417    if( strpos( $str, $substr ) === 0 )
     
    108121            '', 'no' );
    109122        //add and flush rewrite rule
    110         add_rewrite_rule( "goto/([0-9a-z]{4,})", 'index.php?goto=$matches[1]', 'top' );
     123        add_rewrite_rule( "goto/([0-9a-z]{4,})/?$", 'index.php?goto=$matches[1]', 'top' );
    111124        flush_rewrite_rules();
    112125    } else {
  • anylink/trunk/readme.txt

    r836042 r841255  
    55Requires at least: 3.4
    66Tested up to: 3.8
    7 Stable tag: 0.1.5
     7Stable tag: 0.1.6
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4141
    4242== Changelog ==
     43
     44= 0.1.6 =
     45*   Fixed some bugs cause 404 error
     46*   Fixed a bug which may cause collison with other plugins
     47*   修复了一些可能会引起插件造成404错误的bug
     48*   修复了与其他插件存在潜在冲突的bug
    4349
    4450= 0.1.5 =
Note: See TracChangeset for help on using the changeset viewer.