Skip to content

Commit

Permalink
Merge branch 'yourls-1.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerbz committed Aug 25, 2014
2 parents 3c07225 + bd9f35f commit eb45ba0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 55 deletions.
30 changes: 10 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,39 @@
2. I want to use http://sho.rt as my short url but I want to install it at http://longurl.sho.rt

####Requirements
[yourls](http://code.google.com/p/yourls/yourls) [1.5](http://code.google.com/p/yourls/downloads/list) or [1.5.1](http://code.google.com/p/yourls/source/checkout)
[Yourls](https://github.com/YOURLS/YOURLS) [1.7]


####Installation
1. place the **/modify-short-url** directory in yourls **user/plugins** directory
2. set **YOURLS_SITE** to the location of your yourls installation in **config.php**
3. define the short url you wish to share with the public at the end of your **config.php** after "Personal settings..." Example: <code>define( 'YOURLS_SHORT_URL', 'http://shorturl.com' );</code>
4. Modify the **.htaccess** file at the location defined by **YOURLS_SHORT_URL** *(see below)*
5. Activate the plugin by clicking **Manage Plugins** at the top of the admin interface and then clicking **Activate** next to the Swap Short URL plugin

#### Htaccess

### Htaccess
You need to direct traffic from your defined short url to your yourls installation. To do this, create (or modify) an .htaccess file in the directory you defined as your **YOURLS_SHORT_URL** with the following:

<code>
```
RewriteEngine On

<code>
RewriteBase /
<code>
\# BEGIN YOURLS
# BEGIN YOURLS
<code>
RewriteCond %{REQUEST_FILENAME} !-f

<code>
RewriteCond %{REQUEST_FILENAME} !-d
<code>
RewriteRule ^([0-9A-Za-z]+)/?$ http://shorturl.com/yourls/yourls-go.php?id=$1 [L]

<code>
RewriteRule ^([0-9A-Za-z]+)\+/?$ http://shorturl.com/yourls/yourls-infos.php?id=$1 [L]

<code>
RewriteRule ^([0-9A-Za-z]+)\+all/?$ http://shorturl.com/yourls/yourls-infos.php?id=$1&all=1 [L]
<code>
\# END YOURLS
</code>
# END YOURLS
```

#### Issues
.htaccess is tricky and everyon's setup will be slightly different so that part is on you. Otherwise, feel free to submit problems feature requests using the [GitHub issue tracker](https://github.com/ggwarpig/Yourls-Modify-Short-Url/issues)
.htaccess is tricky and everyon's setup will be slightly different so that part is on you. Otherwise, feel free to submit problems feature requests using the [GitHub issue tracker](https://github.com/ggwarpig/Yourls-Swap-Short-Url/issues)


---
developed by [@greg_gerber](http://twitter.com/greg_gerber)
developed by [@gerbz](http://twitter.com/gerbz)
59 changes: 24 additions & 35 deletions swap-short-url/plugin.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
<?php
/*
Plugin Name: Swap Short URL
Plugin URI: http://github.com/ggwarpig/Yourls-Swap-Short-Url/
Plugin URI: http://github.com/ggwarpig/Yourls-Swap-Short-Url
Description: Swap out the shorturls created by yourls if you want to point them somewhere else. This can be tricky! See the <a href="http://github.com/ggwarpig/Yourls-Swap-Short-Url/blob/master/README.md">instructions</a>
Version: 1.0
Version: 1.7
Author: ggwarpig
Author URI: http://gerbz.com
*/

// List of plugin hooks http://yourls.org/hooklist.php

// Modifies shorturl displayed alongside the edit shortcode field on the admin panel
// functions-html.php 364
yourls_add_filter( 'table_edit_row', 'swap_shorturl_table_edit_row' );
// Modifies link to shorturls everywhere
// functions.php 1683
yourls_add_filter( 'yourls_link', 'swap_shorturl_yourls_link' );

function swap_shorturl_table_edit_row( $args ) {
function swap_shorturl_yourls_link( $args ) {
return str_replace( YOURLS_SITE, YOURLS_SHORT_URL, $args );
}

// Modifies the stats action button url
// functions-html.php 524
yourls_add_filter( 'table_add_row_action_array', 'swap_shorturl_table_add_row_action_array' );

function swap_shorturl_table_add_row_action_array( $args ) {

foreach( $args as &$arg ) {
if( $arg['title'] == 'Stats') {
$url = rtrim(ltrim(str_replace( YOURLS_SITE, '', $arg['href'] ),'/'), '+');
$arg['href'] = YOURLS_SITE.'/yourls-infos.php?id='.$url;
break;
}
}

return $args;
}

// Modifies shorturls in share boxes after creating a new link on the admin panel
// functions 261
yourls_add_filter( 'add_new_link', 'swap_shorturl_add_new_link' );
Expand All @@ -28,37 +43,11 @@ function swap_shorturl_add_new_link( $args ) {
return $args;
}

// Modifies link to shorturls from the shortcode in the admin panel
// functions-html.php 448
yourls_add_filter( 'table_add_row', 'swap_shorturl_table_add_row' );

function swap_shorturl_table_add_row( $args ) {
return str_replace( YOURLS_SITE, YOURLS_SHORT_URL, $args );
}

// Modifies shorturls of the response after editing a link
// functions.php 312
// functions.php 367
yourls_add_filter( 'edit_link', 'swap_shorturl_edit_link' );

function swap_shorturl_edit_link( $args ) {
$args['url']['shorturl'] = str_replace( YOURLS_SITE, YOURLS_SHORT_URL, $args['url']['shorturl'] );
return $args;
}

// Modifies shorturls in the shortlink box on the info page
// functions-html.php 276
yourls_add_filter( 'share_box_data', 'swap_shorturl_share_box_data' );

function swap_shorturl_share_box_data( $args ) {
$args = str_replace( YOURLS_SITE, YOURLS_SHORT_URL, $args );
return $args;
}

// Modifies shorturl in the header of the info page
// functions-html.php 1392
yourls_add_filter( 'yourls_link', 'swap_shorturl_yourls_link' );

function swap_shorturl_yourls_link( $args ) {
$args = str_replace( YOURLS_SITE, YOURLS_SHORT_URL, $args );
return $args;
}

0 comments on commit eb45ba0

Please sign in to comment.