Skip to content

Commit

Permalink
Move /pages into /user (YOURLS#2648)
Browse files Browse the repository at this point in the history
Closes YOURLS#1582

* Move `pages/` into `user/`
* Update functions to display pages
* Add tests for pages
* Update .gitignore and robots sample file

Co-authored-by:  Léo Colombaro <[email protected]>
  • Loading branch information
ozh and LeoColomb authored Apr 18, 2020
1 parent 3e084ed commit 556049e
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 9 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ user/*
!user/plugins/sample-toolbar/

# Pages
pages/*
!pages/examplepage.php
!user/pages/examplepage.php

# Keep index.html
!user/index.html
Expand Down
2 changes: 1 addition & 1 deletion includes/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function define_core_constants() {

// physical path of pages directory
if (!defined( 'YOURLS_PAGEDIR' ))
define('YOURLS_PAGEDIR', YOURLS_ABSPATH.'/pages' );
define('YOURLS_PAGEDIR', YOURLS_USERDIR.'/pages' );

// table to store URLs
if (!defined( 'YOURLS_DB_TABLE_URL' ))
Expand Down
12 changes: 8 additions & 4 deletions includes/functions-html.php
Original file line number Diff line number Diff line change
Expand Up @@ -855,18 +855,22 @@ function yourls_notice_box( $message, $style = 'notice' ) {
}

/**
* Display a page
* Display a page
*
* Includes content of a PHP file from the YOURLS_PAGEDIR directory, as if it
* were a standard short URL (ie http://sho.rt/$page)
*
* @since 1.0
* @param $page PHP file to display
*/
function yourls_page( $page ) {
$include = YOURLS_ABSPATH . "/pages/$page.php";
$include = YOURLS_PAGEDIR . "/$page.php";
if( !file_exists( $include ) ) {
yourls_die( "Page '$page' not found", 'Not found', 404 );
yourls_die( yourls_s('Page "%1$s" not found', $page), yourls__('Not found'), 404 );
}
yourls_do_action( 'pre_page', $page );
include_once( $include );
yourls_do_action( 'post_page', $page );
die();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function yourls_keyword_is_reserved( $keyword ) {
$reserved = false;

if ( in_array( $keyword, $yourls_reserved_URL)
or file_exists( YOURLS_ABSPATH ."/pages/$keyword.php" )
or file_exists( YOURLS_PAGEDIR ."/$keyword.php" )
or is_dir( YOURLS_ABSPATH ."/$keyword" )
)
$reserved = true;
Expand Down
1 change: 0 additions & 1 deletion sample-robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ Disallow: /css
Disallow: /images
Disallow: /includes
Disallow: /js
Disallow: /pages
Disallow: /user

1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
define('YOURLS_TESTDATA_DIR', dirname( __FILE__ ) . '/data');
define('YOURLS_LANG_DIR', YOURLS_TESTDATA_DIR.'/pomo');
define('YOURLS_PLUGINDIR', YOURLS_TESTDATA_DIR.'/plugins');
define('YOURLS_PAGEDIR', YOURLS_TESTDATA_DIR.'/pages');
$config = new \YOURLS\Config\Config(YOURLS_CONFIGFILE);
$config->define_core_constants();

Expand Down
4 changes: 4 additions & 0 deletions tests/data/pages/examplepage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

//

25 changes: 25 additions & 0 deletions tests/tests/pages/pages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* Pages
*
* @group pages
*/

class Pages_Tests extends PHPUnit_Framework_TestCase {

public function test_page_is_reserved() {
$this->assertTrue( yourls_keyword_is_reserved('examplepage') );
}

public function test_create_page_and_check_is_reserved() {
$page = rand_str();
if( touch(YOURLS_PAGEDIR . "/$page.php") ) {
$this->assertTrue( yourls_keyword_is_reserved($page) );
unlink(YOURLS_PAGEDIR . "/$page.php");
} else {
$this->markTestSkipped( "Cannot create 'pages/$page'" );
}
}

}
File renamed without changes.
File renamed without changes.

0 comments on commit 556049e

Please sign in to comment.