Plugin Directory

Changeset 836042


Ignore:
Timestamp:
01/10/2014 11:16:28 AM (12 years ago)
Author:
SivaDu
Message:

updated to version 0.1.5

Location:
anylink/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • anylink/trunk/anyLink.php

    r834826 r836042  
    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.4
     6Version: 0.1.5
    77Author: dudo
    88Author URI: http://dudo.org/about
     
    2020$alOption = new al_option();
    2121add_action( 'transition_post_status', 'post_published', 10, 3 );
     22add_action( 'wp_loaded','checkFlush' );
    2223
     24/**
     25 * Check rewrite rules and flush
     26 *
     27 * Checking if rewrite rules are included, if not we should re-flush it;
     28 *
     29 * @see http://codex.wordpress.org/Class_Reference/WP_Rewrite#Examples
     30 * @since version 0.1.5
     31 */
     32function checkFlush(){
     33    $rules = get_option( 'rewrite_rules' );
     34    $alOption = get_option( 'anylink_options' );
     35    $cat = $alOption['redirectCat'];
     36   
     37    if( ! isset( $rules[$cat . '/([0-9a-z]{4,})'] ) ){
     38        global $wp_rewrite;
     39        $wp_rewrite -> flush_rules();
     40    }
     41}
    2342/**
    2443 * This function is to replace old ACTTION hook 'publish_post'
     
    6483        $filter = new al_filter();
    6584        return $filter -> applyFilter( $content );
     85       
    6686    } else {
    6787        return $content;
  • anylink/trunk/classes/al_covert.php

    r834826 r836042  
    3232        return $result;
    3333    }
    34     private function storeExtLnks($arrURLs ) {
     34    public function storeExtLnks( $arrURLs ) {
    3535        global $wpdb;
    3636        $urlIDs = array();
     
    6666        return $urlIDs;
    6767    }
    68     private function storeRel ( $post_id, $arrUrlIDs ) {
     68    public function storeRel ( $post_id, $arrUrlIDs ) {
    6969        global $wpdb;
    7070        $arrOldIndex = array();
  • anylink/trunk/classes/al_filter.php

    r834782 r836042  
    1010    }
    1111    //@post_id: get all links and slugs of a specified post
    12     private function getAllLnks( $post_id ) {
     12    public function getAllLnks( $post_id ) {
    1313        $arrURL = array();
    1414        global $wpdb;
    1515        $arrURL = $wpdb -> get_results( $wpdb -> prepare(
    1616            "
    17             SELECT U.al_slug,U.al_origURL
     17            SELECT U.al_id, U.al_slug,U.al_origURL
    1818            FROM " . ANYLNK_DBINDEX . " I
    1919            LEFT JOIN " . ANYLNK_DBTB . " U
     
    4040        global $wp_query, $wp_rewrite;
    4141        $post_id = get_the_id();
    42         $siteURL = home_url();
    4342        $arrUrlSlug = $this -> getAllLnks( $post_id );
    4443        if( $arrUrlSlug ) {
    4544            foreach( $arrUrlSlug as $arrSlugs ) {
    46                 if( $wp_rewrite -> using_permalinks() )
    47                     $this -> arrU2S[$arrSlugs['al_origURL']] = $siteURL . '/' . $this -> redirectCat . '/' . $arrSlugs['al_slug'];
    48                 else
    49                     $this -> arrU2S[$arrSlugs['al_origURL']] = $siteURL . '/?' . $this -> redirectCat . '=' . $arrSlugs['al_slug'];
     45                $this -> arrU2S[$arrSlugs['al_origURL']] = $this -> getInternalLinkBySlug( $arrSlugs['al_slug'] );
    5046            }
    5147        }
     
    7975        }   
    8076    }
    81     private function getUrlBySlug( $slug ) {
     77    public function getUrlBySlug( $slug ) {
    8278        global $wpdb;
    8379        $URL = $wpdb -> get_var( $wpdb -> prepare(
    8480            "
    8581            SELECT al_origURL
    86             FROM " . ANYLNK_DBTB ."
     82            FROM " . ANYLNK_DBTB . "
    8783            WHERE al_slug = %s",
    8884            $slug
    89         ));
     85        ) );
    9086        return $URL;
     87    }
     88   
     89    public function getSlugById( $id ) {
     90        global $wpdb;
     91        $arrSlug = $wpdb -> get_row( $wpdb -> prepare(
     92            "SELECT *
     93            FROM " . ANYLNK_DBTB . "
     94            WHERE al_id = %s",
     95            $id
     96        ), ARRAY_A );
     97        return $arrSlug;
     98    }
     99   
     100    public function getInternalLinkBySlug( $slug ) {
     101        global $wp_rewrite;
     102        $siteURL = home_url();
     103        if( $wp_rewrite -> using_permalinks() )
     104            $internalLink = $siteURL . '/'  . $this -> redirectCat . '/' . $slug;
     105        else
     106            $internalLink = $siteURL . '/?' . $this -> redirectCat . '=' . $slug;
     107        return $internalLink;
    91108    }
    92109}
  • anylink/trunk/functions.php

    r834843 r836042  
    1212    else
    1313        return false;
     14}
     15
     16/**
     17 * Covert any link to be used as a parameter
     18 *
     19 * if a link is not in an article, you can call method anylink anywhere
     20 * to covert it manually.
     21 *
     22 * @param string $link external link to be covert
     23 * @param integer $postId if the link doesn't belongs any post it will be set to 0
     24 *
     25 * @example call anylink() like this:
     26 * <?
     27 *      echo function_exists('anylink') ? anylink('http://dudo.org', get_the_ID()) : 'http://dudo.org';
     28 * ?>
     29 * @since version 0.1.5
     30 */
     31 
     32function anylink( $link, $postId = 0 ) {
     33    require_once( ANYLNK_PATH . '/config.php' );
     34    require_once( ANYLNK_PATH . '/classes/al_covert.php' );
     35    require_once( ANYLNK_PATH . '/classes/al_filter.php' );
     36    require_once( ANYLNK_PATH . '/classes/al_slug.php' );
     37    require_once( ANYLNK_PATH . '/classes/al_option.php' );
     38   
     39    $covert = new al_covert;
     40    $filter = new al_filter;
     41    $id = $covert -> storeExtLnks( ( array )$link );
     42    //because method storeRel will delete relationships
     43    //so we must get all relationships to compare
     44    $urls = $filter -> getAllLnks( $postId );
     45    if( ! empty( $urls ) ) {
     46        foreach( $urls as $url ){
     47            $oldUrlIds[] = $url['al_id'];
     48        }
     49    }
     50    $urlIds = array_merge( $oldUrlIds, $id );
     51    $covert -> storeRel( $postId, $urlIds );
     52    $objSlug = $filter -> getSlugById( $id );
     53    return $filter -> getInternalLinkBySlug( $objSlug['al_slug'] );
    1454}
    1555//Install
  • anylink/trunk/readme.txt

    r834782 r836042  
    55Requires at least: 3.4
    66Tested up to: 3.8
    7 Stable tag: 0.1.4
     7Stable tag: 0.1.5
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    4141
    4242== Changelog ==
     43
     44= 0.1.5 =
     45*   Add a method anylink() you can call it anywhere. e.g. anylink( 'http://dudo.org', get_the_ID() ) you will get a coverted link
     46*   another example: <? echo function_exists('anylink') ? anylink( $externalUrl, get_the_ID()) : $externalUrl; ?>
     47*   增加了一个 anylink()方法,接受两个参数,第一个为需要转换的链接,第二个为文章ID,如果文章ID为空则默认为0
     48*   使用方法如下 <? echo function_exists('anylink') ? anylink( $externalUrl, get_the_ID()) : $externalUrl; ?>
    4349
    4450= 0.1.4 =
  • anylink/trunk/uninstall.php

    r768798 r836042  
    55    global $wpdb;
    66    $wpdb -> query ( $wpdb -> prepare(
    7             "DROP TABLE  wp_al_urls, wp_al_urls_index", '' ) );
     7            "DROP TABLE " . $wpdb -> prefix . "al_urls, " . $wpdb -> prefix . "al_urls_index") );
    88    delete_option('anylink_options');
    99    flush_rewrite_rules();
Note: See TracChangeset for help on using the changeset viewer.