YOURLS Code Adjustments Page

with 1 Comment

This page talks about the 17 tiny adjustments to YOURLS that make up the little YOURLS-PV Patch.

See the GitHub Page. (Branch PV)

 

Five Different Defined Constants

We did this with just five defined constants. One we reduced a bit, one we expanded a bit, three we added.
The rest of the changes were just plugging in these constants into the code at a dozen or so of the right places.
Most of this is done in load-yourls.php

  • YOURLS_SITE – changed
  • YOURLS_ABSURL – added
  • YOURLS_PROTOCOL – added
  • YOURLS_ADMIN_DIR – added
  • YOURLS_CONFIGFILE – changed

 

YOURLS_SITE

Original YOURLS
1) Provide domain name in Site URLs.
2) Provide subdirectory path in Short URLs.
3) Provide protocol in Short URLs.
4) Provide domain name in Absolute URLs.
5) Provide subdirectory path in Absolute URLs.
6) Provide protocol in Absolute URLs.

YOURLS-PV
1) Provide domain name in Site URLs.
2) Provide subdirectory path in Short URLs.
3) Provide protocol in Short URLs.

 

YOURLS_ABSURL

YOURLS_ABSURL (The absolute URLs – Not in Original YOURLS)
1) Provide domain name in Absolute URLs.
2) Provide subdirectory path in Absolute URLs.
3) Provide protocol in Absolute URLs.

YOURLS_ABSURL is calculated by the program automatically.

 

YOURLS_SITE

YOURLS_SITE can be calculated by the program automatically.
Useful when the redirect server and the admin server running on different protocols.
Short URLs default – to be used for directory format.

Example One
The YOURLS files are loaded into any directory.
Assume you have a site like fil.net/s.
The files would be loaded into the /s directory and YOURLS_SITE also set to fil.net/s
Now say you want to add a multisite called ph2.biz you can’t!
You have no way to reach the /s directory.
Splitting off YOURLS_ABSURL from YOURLS_SITE makes this possible.

Example Two
Say you have a site where you want the redirect services to run on HTTP
And the Admin pages to use HTTPS for better security.
This can only be configured if YOURLS_ABSURL and YOURLS_SITE are split.

 

YOURLS_PROTOCOL

This allows requests to be serviced based on HTTP headers. Also used for proper links.

 

YOURLS_ADMIN_DIR

Used to easily change the admin directory name. Useful for better security, more so in https.
Optionally defined in /user/multisite-config.php.
YOURLS-PV in MultiSite can also use /user/multisite-config.php for common configurations(like a shared database).

 

YOURLS_CONFIGFILE

The Original YOURLS used a /includes/config.php file.

About Version 1.4 this changed to a /user/config.php file.

YOURLS-PV in MultiSite uses a /user/your.domain-config.php file.
Something like /user/fyuel.org-config.php or /user/vekind.org-config.php

YOURLS-PV is backward compatible to serve as a single YOURLS.

 

YOURLS-PV Patch Changes

 

 

Program Changes Made

(Commented “YOURLS-PV”)

admin/tools.php (4 changes)
includes/YOURLS/Config/Config.php (8 changes)
includes/functions.php (3 changes)
includes/load-yourls.php (1 change)
yourls-infos.php (1 change)

 

Total Program Changes Made (17 changes)

 

Sample/Example Pages Changed

(Commented “YOURLS-PV”)

pages/examplepage.php (1)
sample-public-front-page.txt (1)

 

Sample Page Added

 

user/sample-multisite-config.php (Added)

Read More…

 

Stop Reading

 

With the addition of Config.php and the Config Class in YOURLS, the following is obsolete.

View the changes on GitHub (Branch PV).

 

Adjusted Files

Totals = 17 adjustments in 7 files

1) /admin/tools.php (4)
2) /includes/functions.php (3)
3) /includes/load-yourls.php (7)
4) /pages/examplepage.php (1)
5) /user/multisite-config.php (added)
6) /sample-public-front-page.txt (1)
7) /yourls-infos.php (1)

 

1) /admin/tools.php (4)

 

1.1

<?php/* LANMARK YOURLS__SITE to YOURLS_ABSURL */ ?>
<?php/* <p><code><?php echo YOURLS_SITE; ?>/yourls-api.php?signature=<?php echo yourls_auth_signature(); ?>&action=…</code></p> */ ?>
<p><code><?php echo YOURLS_ABSURL; ?>/yourls-api.php?signature=<?php echo yourls_auth_signature(); ?>&action=…</code></p>

 

1.2

<?php/* LANMARK YOURLS__SITE to YOURLS_ABSURL */ ?>
<?php/*
<p><code><?php echo YOURLS_SITE; ?>/yourls-api.php?timestamp=<strong>$timestamp</strong>&signature=<strong>$signature</strong>&action=…</code></p> */ ?>
<p><code><?php echo YOURLS_ABSURL; ?>/yourls-api.php?timestamp=<strong>$timestamp</strong>&signature=<strong>$signature</strong>&action=…</code></p>

 

1.3

<?php/* LANMARK YOURLS__SITE to YOURLS_ABSURL */ ?>
<?php/* <tt><?php echo YOURLS_SITE; ?>/yourls-api.php?timestamp=<?php echo $time; ?>&signature=<?php echo $sign; ?>&action=…</tt></p> */ ?>
<tt><?php echo YOURLS_ABSURL; ?>/yourls-api.php?timestamp=<?php echo $time; ?>&signature=<?php echo $sign; ?>&action=…</tt></p>

 

1.4

<?php/* LANMARK YOURLS__SITE to YOURLS_ABSURL */ ?>
<?php/*
<p><?php yourls_se( ‘See the <a href=”%s”>API documentation</a> for more’, YOURLS_SITE . ‘/readme.html#API’ ); ?></p> */ ?>
<p><?php yourls_se( ‘See the <a href=”%s”>API documentation</a> for more’, YOURLS_ABSURL . ‘/readme.html#API’ ); ?></p>

 

2) /includes/functions.php (3)

 

2.1

/* LANMARK YOURLS__SITE to YOURLS_ABSURL */
/* $img = yourls_match_current_protocol( YOURLS_SITE.’/includes/geo/flags/flag_’.( strtolower( $code ) ).’.gif’ ); */
$img = yourls_match_current_protocol( YOURLS_ABSURL . ‘/includes/geo/flags/flag_’.( strtolower( $code ) ).’.gif’ );

 

2.2

/* LANMARK YOURLS__SITE to YOURLS_ABSURL and YOURLS_ADMIN_DIR */
/* $admin = YOURLS_SITE . ‘/admin/’ . $page; */
$admin = YOURLS_ABSURL . YOURLS_ADMIN_DIR . ‘/’ . $page;

 

2.3

/* LANMARK YOURLS__SITE to YOURLS_ABSURL */
/* $url = trim( YOURLS_SITE . ‘/’ . $url, ‘/’ ); */
$url = trim( YOURLS_ABSURL . ‘/’ . $url, ‘/’ );

 

3) /includes/load-yourls.php (7)

See the new page on GitHub, search for LANMARK.
This is where most changes take place.

 

3.1

Replace Old “Include settings” for Multisite
Define YOURLS_PROTOCOL as http:// or https://
Accurately determine the protocol from the HTTP request headers across platforms.
Define YOURLS_CONFIGFILE with MultiSite Format.
See the new /includes/load-yourls.php page

 

3.2

// LANMARK Include multisite settings – Load the /user/multisite-config file.
if( file_exists( dirname( __DIR__ ) . ‘/user/multisite-config.php’ ) )
require_once( dirname( __DIR__ ) . ‘/user/multisite-config.php’ );

 

3.3

// LANMARK Check if config.php – YOURLS_SITE has a trailing slash error.
// W3C – Valid HTML5 – Valid CSS3 – Valid Links
if( defined( ‘YOURLS_SITE’ ) && ‘/’ == substr( YOURLS_SITE, -1 ) )
die – See the new /includes/load-yourls.php page

 

3.4

/*
* LANMARK YOURLS_ABSURL
*
* ABSolute URL of the YOURLS directory
*
* See the new /includes/load-yourls.php page
*/

if ( !defined( ‘YOURLS_ABSURL’ ) )
define( ‘YOURLS_ABSURL’, YOURLS_PROTOCOL . $_SERVER[‘HTTP_HOST’] . substr( YOURLS_ABSPATH, strlen( $_SERVER[ ‘DOCUMENT_ROOT’ ] ) ) );

 

3.5

/*
* LANMARK YOURLS_ADMIN_DIR
*
* Allows the admin directory to be renamed in any config file.
*
* Defult: /admin
*/

if( !defined( ‘YOURLS_ADMIN_DIR’ ) )
define( ‘YOURLS_ADMIN_DIR’, ‘/admin’ );

 

3.6

/*
* LANMARK YOURLS_SITE
*
* Used solely to format shortened URLs
*/

if ( !defined( ‘YOURLS_SITE’ ) )
define( ‘YOURLS_SITE’, YOURLS_PROTOCOL . $_SERVER[‘HTTP_HOST’] );

 

3.7

/* LANMARK Replace YOURLS__SITE with YOURLS_ABSURL */
/* define( ‘YOURLS_USERURL’, YOURLS_SITE.’/user’ ); */
define( ‘YOURLS_USERURL’, YOURLS_ABSURL . ‘/user’ );

 

4) /pages/examplepage.php (1)

 

4.1

/* LANMARK YOURLS__SITE to YOURLS_ABSURL */
/*
$url = YOURLS_SITE . ‘/examplepage’; */
$url = YOURLS_ABSURL . ‘/examplepage’;

 

5) /user/multisite-config.php (added)

 

5.1

Optional – This file may be added for MultiSite Operations.
It definds default configurations for All Sites.
These defaults may be overridden by individual site config files.

 

6) /sample-public-front-page.txt (1)

 

6.1

/* LANMARK YOURLS__SITE to YOURLS_ABSURL */
/*
$page = YOURLS_SITE . ‘/sample-public-front-page.php’ ; */
$page = YOURLS_ABSURL . ‘/sample-public-front-page.php’ ;

 

7) /yourls-infos.php (1)

 

7.1

/* LANMARK YOURLS__SITE to YOURLS_ABSURL */
/* echo ‘ <a href=”‘. yourls_link($keyword).’+all” title=”‘ . yourls_esc_attr__( ‘Aggregate stats for duplicate short URLs’ ) . ‘”><img src=”‘ . yourls_match_current_protocol( YOURLS_SITE ) . ‘/images/chart_bar_add.png” border=”0″ /></a>’; */
echo ‘ <a href=”‘. yourls_link($keyword).’+all” title=”‘ . yourls_esc_attr__( ‘Aggregate stats for duplicate short URLs’ ) . ‘”><img src=”‘ . yourls_match_current_protocol( YOURLS_ABSURL ) . ‘/images/chart_bar_add.png” border=”0″ /></a>’;

One Response

  1. WordPress Admin
    | Reply

    Hi, this is GREAT!

    Looking forward to trying YOURLS-PV in MultiSite Mode. Will you be posting config information?

Leave a Reply