Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* @package WPSEO | ||
*/ | ||
|
||
/** | ||
* Helps with creating shortlinks in the plugin | ||
*/ | ||
class WPSEO_Shortlinker { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $version; | ||
|
||
/** | ||
* @param string $version The version to put in the utm_content tag. | ||
*/ | ||
public function __construct( $version ) { | ||
$this->version = $version; | ||
} | ||
|
||
/** | ||
* Builds a URL to use in the plugin as shortlink. | ||
* | ||
* @param string $url The URL to build upon. | ||
* | ||
* @return string The final URL. | ||
*/ | ||
public function build_shortlink( $url ) { | ||
return $url . '?utm_content=' . $this->version; | ||
} | ||
|
||
/** | ||
* Returns a version of the URL with a utm_content with the current version. | ||
* | ||
* @param string $url The URL to build upon. | ||
* | ||
* @return string The final URL. | ||
*/ | ||
public static function get( $url ) { | ||
$version = WPSEO_VERSION; | ||
|
||
$version = apply_filters( 'wpseo_shortlink_version', $version ); | ||
|
||
$shortlinker = new WPSEO_Shortlinker( $version ); | ||
|
||
return $shortlinker->build_shortlink( $url ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
|
||
class WPSEO_Shortlinker_Test extends PHPUnit_Framework_TestCase { | ||
|
||
public function test_build_shortlink() { | ||
$shortlinks = new WPSEO_Shortlinker( 'version' ); | ||
|
||
$shortlink = $shortlinks->build_shortlink( 'http://yoa.st/abcdefg' ); | ||
|
||
$this->assertEquals( 'http://yoa.st/abcdefg?utm_content=version', $shortlink ); | ||
} | ||
|
||
public function test_get() { | ||
$shortlink = WPSEO_Shortlinker::get( 'http://yoa.st/blaat' ); | ||
|
||
$this->assertEquals( 'http://yoa.st/blaat?utm_content=' . WPSEO_VERSION, $shortlink ); | ||
} | ||
} |