Move /pages into /user (#2648)
Closes #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 <git@colombaro.fr>
This commit is contained in:
parent
3e084ed67a
commit
556049e28b
3
.gitignore
vendored
3
.gitignore
vendored
@ -24,8 +24,7 @@ user/*
|
|||||||
!user/plugins/sample-toolbar/
|
!user/plugins/sample-toolbar/
|
||||||
|
|
||||||
# Pages
|
# Pages
|
||||||
pages/*
|
!user/pages/examplepage.php
|
||||||
!pages/examplepage.php
|
|
||||||
|
|
||||||
# Keep index.html
|
# Keep index.html
|
||||||
!user/index.html
|
!user/index.html
|
||||||
|
@ -163,7 +163,7 @@ class Config {
|
|||||||
|
|
||||||
// physical path of pages directory
|
// physical path of pages directory
|
||||||
if (!defined( 'YOURLS_PAGEDIR' ))
|
if (!defined( 'YOURLS_PAGEDIR' ))
|
||||||
define('YOURLS_PAGEDIR', YOURLS_ABSPATH.'/pages' );
|
define('YOURLS_PAGEDIR', YOURLS_USERDIR.'/pages' );
|
||||||
|
|
||||||
// table to store URLs
|
// table to store URLs
|
||||||
if (!defined( 'YOURLS_DB_TABLE_URL' ))
|
if (!defined( 'YOURLS_DB_TABLE_URL' ))
|
||||||
|
@ -855,18 +855,22 @@ HTML;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 ) {
|
function yourls_page( $page ) {
|
||||||
$include = YOURLS_ABSPATH . "/pages/$page.php";
|
$include = YOURLS_PAGEDIR . "/$page.php";
|
||||||
if( !file_exists( $include ) ) {
|
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 );
|
yourls_do_action( 'pre_page', $page );
|
||||||
include_once( $include );
|
include_once( $include );
|
||||||
yourls_do_action( 'post_page', $page );
|
yourls_do_action( 'post_page', $page );
|
||||||
die();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +68,7 @@ function yourls_keyword_is_reserved( $keyword ) {
|
|||||||
$reserved = false;
|
$reserved = false;
|
||||||
|
|
||||||
if ( in_array( $keyword, $yourls_reserved_URL)
|
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" )
|
or is_dir( YOURLS_ABSPATH ."/$keyword" )
|
||||||
)
|
)
|
||||||
$reserved = true;
|
$reserved = true;
|
||||||
|
@ -4,6 +4,5 @@ Disallow: /css
|
|||||||
Disallow: /images
|
Disallow: /images
|
||||||
Disallow: /includes
|
Disallow: /includes
|
||||||
Disallow: /js
|
Disallow: /js
|
||||||
Disallow: /pages
|
|
||||||
Disallow: /user
|
Disallow: /user
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ require_once YOURLS_ABSPATH . '/includes/vendor/autoload.php';
|
|||||||
define('YOURLS_TESTDATA_DIR', dirname( __FILE__ ) . '/data');
|
define('YOURLS_TESTDATA_DIR', dirname( __FILE__ ) . '/data');
|
||||||
define('YOURLS_LANG_DIR', YOURLS_TESTDATA_DIR.'/pomo');
|
define('YOURLS_LANG_DIR', YOURLS_TESTDATA_DIR.'/pomo');
|
||||||
define('YOURLS_PLUGINDIR', YOURLS_TESTDATA_DIR.'/plugins');
|
define('YOURLS_PLUGINDIR', YOURLS_TESTDATA_DIR.'/plugins');
|
||||||
|
define('YOURLS_PAGEDIR', YOURLS_TESTDATA_DIR.'/pages');
|
||||||
$config = new \YOURLS\Config\Config(YOURLS_CONFIGFILE);
|
$config = new \YOURLS\Config\Config(YOURLS_CONFIGFILE);
|
||||||
$config->define_core_constants();
|
$config->define_core_constants();
|
||||||
|
|
||||||
|
4
tests/data/pages/examplepage.php
Normal file
4
tests/data/pages/examplepage.php
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
//
|
||||||
|
|
25
tests/tests/pages/pages.php
Normal file
25
tests/tests/pages/pages.php
Normal file
@ -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'" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user