Changeset 836042
- Timestamp:
- 01/10/2014 11:16:28 AM (12 years ago)
- Location:
- anylink/trunk
- Files:
-
- 6 edited
-
anyLink.php (modified) (3 diffs)
-
classes/al_covert.php (modified) (2 diffs)
-
classes/al_filter.php (modified) (3 diffs)
-
functions.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
anylink/trunk/anyLink.php
r834826 r836042 4 4 Plugin URI: http://dudo.org/anylink 5 5 Description: 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. 46 Version: 0.1.5 7 7 Author: dudo 8 8 Author URI: http://dudo.org/about … … 20 20 $alOption = new al_option(); 21 21 add_action( 'transition_post_status', 'post_published', 10, 3 ); 22 add_action( 'wp_loaded','checkFlush' ); 22 23 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 */ 32 function 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 } 23 42 /** 24 43 * This function is to replace old ACTTION hook 'publish_post' … … 64 83 $filter = new al_filter(); 65 84 return $filter -> applyFilter( $content ); 85 66 86 } else { 67 87 return $content; -
anylink/trunk/classes/al_covert.php
r834826 r836042 32 32 return $result; 33 33 } 34 p rivate function storeExtLnks($arrURLs ) {34 public function storeExtLnks( $arrURLs ) { 35 35 global $wpdb; 36 36 $urlIDs = array(); … … 66 66 return $urlIDs; 67 67 } 68 p rivatefunction storeRel ( $post_id, $arrUrlIDs ) {68 public function storeRel ( $post_id, $arrUrlIDs ) { 69 69 global $wpdb; 70 70 $arrOldIndex = array(); -
anylink/trunk/classes/al_filter.php
r834782 r836042 10 10 } 11 11 //@post_id: get all links and slugs of a specified post 12 p rivatefunction getAllLnks( $post_id ) {12 public function getAllLnks( $post_id ) { 13 13 $arrURL = array(); 14 14 global $wpdb; 15 15 $arrURL = $wpdb -> get_results( $wpdb -> prepare( 16 16 " 17 SELECT U.al_ slug,U.al_origURL17 SELECT U.al_id, U.al_slug,U.al_origURL 18 18 FROM " . ANYLNK_DBINDEX . " I 19 19 LEFT JOIN " . ANYLNK_DBTB . " U … … 40 40 global $wp_query, $wp_rewrite; 41 41 $post_id = get_the_id(); 42 $siteURL = home_url();43 42 $arrUrlSlug = $this -> getAllLnks( $post_id ); 44 43 if( $arrUrlSlug ) { 45 44 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'] ); 50 46 } 51 47 } … … 79 75 } 80 76 } 81 p rivatefunction getUrlBySlug( $slug ) {77 public function getUrlBySlug( $slug ) { 82 78 global $wpdb; 83 79 $URL = $wpdb -> get_var( $wpdb -> prepare( 84 80 " 85 81 SELECT al_origURL 86 FROM " . ANYLNK_DBTB . "82 FROM " . ANYLNK_DBTB . " 87 83 WHERE al_slug = %s", 88 84 $slug 89 ) );85 ) ); 90 86 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; 91 108 } 92 109 } -
anylink/trunk/functions.php
r834843 r836042 12 12 else 13 13 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 32 function 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'] ); 14 54 } 15 55 //Install -
anylink/trunk/readme.txt
r834782 r836042 5 5 Requires at least: 3.4 6 6 Tested up to: 3.8 7 Stable tag: 0.1. 47 Stable tag: 0.1.5 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 41 41 42 42 == 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; ?> 43 49 44 50 = 0.1.4 = -
anylink/trunk/uninstall.php
r768798 r836042 5 5 global $wpdb; 6 6 $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") ); 8 8 delete_option('anylink_options'); 9 9 flush_rewrite_rules();
Note: See TracChangeset
for help on using the changeset viewer.