v4.2.1 #1
@ -1,96 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<!--[if IE 7]>
|
||||
<html class="ie ie7" <?php language_attributes(); ?>>
|
||||
<![endif]-->
|
||||
<!--[if IE 8]>
|
||||
<html class="ie ie8" <?php language_attributes(); ?>>
|
||||
<![endif]-->
|
||||
<!--[if !(IE 7) | !(IE 8) ]><!-->
|
||||
<html <?php language_attributes(); ?>>
|
||||
<!--<![endif]-->
|
||||
<head>
|
||||
<meta charset="<?php bloginfo( 'charset' ); ?>" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="shortcut icon" href="<?php echo esc_url( get_template_directory_uri() ); ?>/img/favicon.ico" />
|
||||
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
|
||||
<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
|
||||
<?php wp_head(); ?>
|
||||
</head>
|
||||
<!-- FIXME: Mehr ARIA role setzen -->
|
||||
<body <?php body_class(); ?>>
|
||||
<div id="wrap"><!-- FIXME: Klassen hfeed, site? -->
|
||||
<header id="header" role="banner"><!-- FIXME: Klasse site-header? -->
|
||||
<hgroup id="branding">
|
||||
<h1 class="site-title">
|
||||
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php _e( 'Zurück zur Startseite', 'buena-theme' ); ?>">
|
||||
<img alt="Bund der Pfadfinderinnen und Pfadfinder" src="<?php echo esc_url( get_template_directory_uri() ); ?>/img/bundeszeichen.png" srcset="<?php echo esc_url( get_template_directory_uri() ); ?>/img/bundeszeichen.png 1x, <?php echo esc_url( get_template_directory_uri() ); ?>/img/bundeszeichen@2x.png 2x" width="390" height="79" />
|
||||
</a>
|
||||
</h1>
|
||||
<h2 class="site-description">
|
||||
<?php echo esc_html( get_bloginfo( 'name', 'display' ) ); ?>
|
||||
</h2>
|
||||
</hgroup>
|
||||
<nav class="screen-reader-text">
|
||||
<!-- FIXME: Tollere Navigation ausdenken -->
|
||||
<a href="#content">
|
||||
<?php _e( 'Zum Inhalt springen', 'buena-theme' ); ?>
|
||||
</a>
|
||||
</nav>
|
||||
<?php do_action( 'buena_search_form' ); ?>
|
||||
</header>
|
||||
<div id="left">
|
||||
<?php wp_nav_menu( [ 'theme_location' => 'primary', 'depth' => 2, 'container' => 'nav', 'container_class' => 'nav-menu' ] ); ?>
|
||||
<?php if ( is_active_sidebar( 'below-navigation' ) ): ?>
|
||||
<ul class="widgets">
|
||||
<?php dynamic_sidebar( 'below-navigation' ); ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div id="teaser">
|
||||
<?php if ( is_page() || have_posts() && is_single() ): the_post(); ?>
|
||||
<?php if ( has_post_thumbnail() ): ?>
|
||||
<?php the_post_thumbnail( 'poster', [ 'alt' => '' ] ); ?>
|
||||
<?php else: ?>
|
||||
<img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
|
||||
<?php endif; ?>
|
||||
<div id="teaserTitle">
|
||||
<h2><?php the_title(); ?></h2>
|
||||
</div>
|
||||
<?php rewind_posts(); ?>
|
||||
<?php elseif ( get_header_image() ): ?>
|
||||
<img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
|
||||
<div id="teaserTitle">
|
||||
<h2><?php bloginfo( 'description' ); ?></h2>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<div id="main" role="main">
|
||||
<div id="content">
|
||||
<?php if ( have_posts() ): ?>
|
||||
<?php while ( have_posts() ): the_post(); ?>
|
||||
<?php get_template_part( 'content', get_post_format() ); ?>
|
||||
<?php endwhile; ?>
|
||||
<?php else: // FIXME: Wenn berechtigt: Erstellen anbieten ?>
|
||||
<article id="post-0" class="post no-results not-found">
|
||||
<?php _e( 'Nicht gefunden.', 'buena-theme' ); ?>
|
||||
</article>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<nav class="pagination">
|
||||
<div class="previous"><?php previous_posts_link( __( '« Neuere Beiträge', 'buena-theme' ) ); ?></div>
|
||||
<div class="next"><?php next_posts_link( __( 'Ältere Beiträge »', 'buena-theme' ) ); ?></div>
|
||||
</nav>
|
||||
<?php comments_template(); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php if ( is_active_sidebar( 'footer' ) ): ?>
|
||||
<footer id="footer">
|
||||
<ul class="widgets">
|
||||
<?php dynamic_sidebar( 'footer' ); ?>
|
||||
</ul>
|
||||
</footer>
|
||||
<?php endif; ?>
|
||||
<?php wp_footer(); ?>
|
||||
</body>
|
||||
</html>
|
@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
if ( post_password_required() ) {
|
||||
printf( '<p class="nocomments">%s</p>', __( 'Kommentare werden erst angezeigt, wenn das Kennwort eingegeben wurde.', 'buena-theme' ) );
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: Hier sollten die Social-Media-Knöpfe auftauchen…
|
||||
|
||||
?>
|
||||
<div class="comments">
|
||||
<?php if ( have_comments() ) : ?>
|
||||
<h4 id="comments"><?php comments_number( 'Keine Kommentare', 'Ein Kommentar', '% Kommentare' );?></h4>
|
||||
<ul class="commentlist">
|
||||
<?php wp_list_comments(); ?>
|
||||
</ul>
|
||||
<nav class="pagination">
|
||||
<div class="alignleft"><?php previous_comments_link() ?></div>
|
||||
<div class="alignright"><?php next_comments_link() ?></div>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
<?php if ( comments_open() ) : ?>
|
||||
<?php comment_form(); ?>
|
||||
<?php else: ?>
|
||||
<p class="nocomments screen-reader-text"><?php _e( 'Es kann nicht kommentiert werden.', 'buena-theme' ); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
@ -1,17 +0,0 @@
|
||||
<article id="post-<?php the_ID(); ?>" <?php post_class( 'clearfix' ); ?>>
|
||||
<?php if ( is_singular() ): ?>
|
||||
<?php the_content(); ?>
|
||||
<p><?php the_tags(); ?></p>
|
||||
<?php wp_link_pages( array( 'before' => '<nav class="page-links">Seiten:', 'after' => '</nav>' ) ); ?>
|
||||
<?php else: ?>
|
||||
<a class="h h-box h-box-blaugelb<?php if ( ! has_post_thumbnail() ): ?> h-box-blaugelb-bildlos<?php endif; ?>" href="<?php echo esc_url( get_permalink() ); ?>">
|
||||
<?php the_post_thumbnail( 'gallery-thumb', [ 'alt' => '' ] ); ?>
|
||||
<?php if ( get_the_title() ): ?>
|
||||
<header class="wrap">
|
||||
<h3><?php the_title(); ?></h3>
|
||||
</header>
|
||||
<?php endif; ?>
|
||||
</a>
|
||||
<?php has_excerpt() ? the_excerpt() : the_content(); ?>
|
||||
<?php endif; ?>
|
||||
</article>
|
@ -1,89 +0,0 @@
|
||||
<?php
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
die( 'I’m a theme.' );
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'trigger_pfadfinden_plugin_error' ) ) {
|
||||
/**
|
||||
* Show an error message.
|
||||
*
|
||||
* @see http://www.squarepenguin.com/wordpress/?p=6 Inspiration
|
||||
*
|
||||
* @param string $message
|
||||
* @param int $type optional
|
||||
* @return bool
|
||||
*/
|
||||
function trigger_pfadfinden_plugin_error( $message, $type = 0 )
|
||||
{
|
||||
if ( isset( $_GET['action'] ) && 'error_scrape' === $_GET['action'] ) {
|
||||
echo $message;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( ! $type ) {
|
||||
$type = E_USER_WARNING;
|
||||
}
|
||||
|
||||
return trigger_error( $message, $type );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check for suitable environment
|
||||
if ( defined( 'PHP_VERSION_ID' ) && PHP_VERSION_ID >= 50400 ) {
|
||||
// Register autoloader if updater plugin missing
|
||||
if ( ! class_exists( 'plugins\buena\use\shy-wordpress\src\Shy\WordPress\Theme' ) ) {
|
||||
if ( ! include_once __DIR__ . '/use/shy-wordpress/src/autoloader.php' ) {
|
||||
trigger_pfadfinden_plugin_error(
|
||||
__( 'Das Theme ist unvollständig und konnte nicht geladen werden. Neuinstallation müsste helfen.', 'buena-theme' ),
|
||||
E_USER_ERROR
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Register our autoloader
|
||||
if ( ! include_once __DIR__ . '/src/autoloader.php' ) {
|
||||
trigger_pfadfinden_plugin_error(
|
||||
__( 'Das Theme ist unvollständig und konnte nicht geladen werden. Neuinstallation müsste helfen.', 'buena-theme' ),
|
||||
E_USER_ERROR
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \plugins\buena\src\Pfadfinden\WordPress\BuenaTheme
|
||||
*/
|
||||
function buena_get_theme()
|
||||
{
|
||||
static $theme = null;
|
||||
if (!$theme) {
|
||||
$theme = new ReflectionClass( 'plugins\buena\src\Pfadfinden\WordPress\BuenaTheme' );
|
||||
$theme = $theme->newInstance();
|
||||
}
|
||||
|
||||
return $theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @return callable
|
||||
*/
|
||||
function buena_get_callback( $method )
|
||||
{
|
||||
return array( buena_get_theme(), (string) $method );
|
||||
}
|
||||
|
||||
return buena_get_theme();
|
||||
}
|
||||
|
||||
|
||||
// Display error message
|
||||
trigger_pfadfinden_plugin_error(
|
||||
sprintf(
|
||||
__( 'You need at least PHP 5.4 to use the Buena theme. Your are using %s.', 'buena-theme' ),
|
||||
PHP_VERSION
|
||||
),
|
||||
E_USER_ERROR
|
||||
);
|
106
buena/index.php
106
buena/index.php
@ -1,106 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<!--[if IE 7]>
|
||||
<html class="ie ie7" <?php language_attributes(); ?>>
|
||||
<![endif]-->
|
||||
<!--[if IE 8]>
|
||||
<html class="ie ie8" <?php language_attributes(); ?>>
|
||||
<![endif]-->
|
||||
<!--[if !(IE 7) | !(IE 8) ]><!-->
|
||||
<html <?php language_attributes(); ?>>
|
||||
<!--<![endif]-->
|
||||
<head>
|
||||
<meta charset="<?php bloginfo( 'charset' ); ?>" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<?php if ( ! function_exists( 'has_site_icon' ) || ! has_site_icon() ): // FIXME: Remove workaround on 2016-02-16 ?>
|
||||
<link rel="shortcut icon" href="<?php echo esc_url( get_template_directory_uri() ); ?>/img/favicon.ico" />
|
||||
<?php endif; ?>
|
||||
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
|
||||
<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>
|
||||
<?php wp_head(); ?>
|
||||
</head>
|
||||
<!-- FIXME: Mehr ARIA role setzen -->
|
||||
<body <?php body_class(); ?>>
|
||||
<div id="wrap"><!-- FIXME: Klassen hfeed, site? -->
|
||||
<header id="header" role="banner"><!-- FIXME: Klasse site-header? -->
|
||||
<hgroup id="branding">
|
||||
<h1 class="site-title">
|
||||
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php _e( 'Zurück zur Startseite', 'buena-theme' ); ?>">
|
||||
<img alt="Bund der Pfadfinderinnen und Pfadfinder" src="<?php echo esc_url( get_template_directory_uri() ); ?>/img/bundeszeichen.png" srcset="<?php echo esc_url( get_template_directory_uri() ); ?>/img/bundeszeichen.png 1x, <?php echo esc_url( get_template_directory_uri() ); ?>/img/bundeszeichen@2x.png 2x" width="390" height="79" />
|
||||
</a>
|
||||
</h1>
|
||||
<h2 class="site-description">
|
||||
<?php echo esc_html( get_bloginfo( 'name', 'display' ) ); ?>
|
||||
</h2>
|
||||
</hgroup>
|
||||
<nav>
|
||||
<!-- FIXME: Tollere Navigation ausdenken -->
|
||||
<a href="#content" class="screen-reader-text"><?php _e( 'Zum Inhalt springen', 'buena-theme' ); ?></a>
|
||||
<button type="button" id="responsiveMenu" title="<?php esc_attr_e( 'Menü', 'buena-theme' ); ?>">
|
||||
<img alt="<?php esc_attr_e( 'Menü', 'buena-theme' ); ?>" src="<?php echo esc_url( get_template_directory_uri() ); ?>/img/hamburger.png" width="32" height="32" />
|
||||
</button>
|
||||
</nav>
|
||||
<?php do_action( 'buena_search_form' ); ?>
|
||||
</header>
|
||||
<div id="left">
|
||||
<?php wp_nav_menu( [ 'theme_location' => 'primary', 'depth' => 2, 'container' => 'nav', 'container_class' => 'nav-menu nav-menu-primary' ] ); ?>
|
||||
<?php if ( is_active_sidebar( 'below-navigation' ) ): ?>
|
||||
<ul class="widgets">
|
||||
<?php dynamic_sidebar( 'below-navigation' ); ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if ( $buenaTeaserImage = buena_get_theme()->getTeaserImage() ): ?>
|
||||
<header class="h h-box h-box-teaser">
|
||||
<?php echo $buenaTeaserImage; ?>
|
||||
<hgroup class="wrap">
|
||||
<h2><?php buena_get_theme()->printTitle(); ?></h2>
|
||||
</hgroup>
|
||||
</header>
|
||||
<?php else: ?>
|
||||
<header class="h">
|
||||
<h2><?php buena_get_theme()->printTitle(); ?></h2>
|
||||
</header>
|
||||
<?php endif; ?>
|
||||
<div id="main" role="main" class="container">
|
||||
<div id="content" class="content-<?php if ( is_singular() ): ?>singular<?php else: ?>gallery<?php endif; ?>">
|
||||
<?php if ( have_posts() ): ?>
|
||||
<?php while ( have_posts() ): the_post(); ?>
|
||||
<?php get_template_part( 'content', get_post_format() ); ?>
|
||||
<?php endwhile; ?>
|
||||
<?php else: // FIXME: Wenn berechtigt: Erstellen anbieten ?>
|
||||
<article id="post-0" class="post no-results not-found">
|
||||
<?php _e( 'Nicht gefunden.', 'buena-theme' ); ?>
|
||||
</article>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<nav class="pagination">
|
||||
<div class="alignright"><?php next_posts_link( __( 'Ältere Beiträge »', 'buena-theme' ) ); ?></div>
|
||||
<div class="alignleft"><?php previous_posts_link( __( '« Neuere Beiträge', 'buena-theme' ) ); ?></div>
|
||||
</nav>
|
||||
<?php comments_template(); ?>
|
||||
</div>
|
||||
</div>
|
||||
<footer id="footer">
|
||||
<div class="wrapper media">
|
||||
<?php if ( is_active_sidebar( 'footer' ) || has_nav_menu( 'footer' ) ): ?>
|
||||
<header class="h">
|
||||
<?php echo esc_html( get_bloginfo( 'name', 'display' ) ?: 'Bund der Pfadfinderinnen und Pfadfinder e.V.' ); ?>
|
||||
</header>
|
||||
<?php wp_nav_menu( [ 'theme_location' => 'footer', 'container' => 'nav', 'container_class' => 'nav-menu nav-menu-footer alignleft', 'fallback_cb' => '' ] ); ?>
|
||||
<ul class="widgets bd">
|
||||
<?php dynamic_sidebar( 'footer' ); ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</footer>
|
||||
<script>
|
||||
+function() {
|
||||
document.getElementById('responsiveMenu').addEventListener('click', function() {
|
||||
document.body.classList.toggle('show-responsive-menu');
|
||||
});
|
||||
}();
|
||||
</script>
|
||||
<?php wp_footer(); ?>
|
||||
</body>
|
||||
</html>
|
@ -1,11 +0,0 @@
|
||||
<form role="search" method="get" class="search-form" action="<?php echo home_url( '/' ); ?>">
|
||||
<label>
|
||||
<span class="screen-reader-text"><?php echo _x( 'Search for:', 'label' ); ?></span>
|
||||
<?php if ( doing_action( 'buena_search_form' ) ): ?>
|
||||
<input type="search" class="search-field" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ); ?>" />
|
||||
<?php else: ?>
|
||||
<input type="search" class="search-field" placeholder="<?php echo esc_attr_x( 'Search …', 'placeholder' ); ?>" value="<?php echo get_search_query(); ?>" name="s" title="<?php echo esc_attr_x( 'Search for:', 'label' ); ?>" />
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
<button type="submit" class="search-submit" title="<?php esc_attr_e( 'Query search', 'buena-theme' ); ?>"><?php echo esc_html_x( 'Search', 'submit button' ); ?></button>
|
||||
</form>
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Try to load a Pfadfinden WordPress class.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
function buena_autoloader( $name )
|
||||
{
|
||||
if ( substr( $name, 0, 21 ) !== 'Pfadfinden\\WordPress\\' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$name = __DIR__ . '/' . str_replace( '\\', DIRECTORY_SEPARATOR, $name ) . '.php';
|
||||
return is_file( $name ) && include( $name );
|
||||
}
|
||||
|
||||
spl_autoload_register( 'buena_autoloader' );
|
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugins\buena\use\shy-wordpress\src\Shy\WordPress;
|
||||
|
||||
|
||||
|
||||
use plugins\buena\use\shy/**
|
||||
* A composite option with a fixed number of suboptions and their default values.
|
||||
*/
|
||||
abstract class CompositeOption implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
{
|
||||
use HookableTrait;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $slug;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSlug()
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
|
||||
protected function __construct( $slug )
|
||||
{
|
||||
$this->slug = (string) $slug;
|
||||
|
||||
$this->addHookMethod( 'default_option_' . $this->slug, 'getDefaults' );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return default values for all suboptions.
|
||||
* Hooked into get_option() defaults.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getDefaults();
|
||||
|
||||
/**
|
||||
* @param string $offset
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDefault( $offset )
|
||||
{
|
||||
return $this->getDefaults()[ $offset ];
|
||||
}
|
||||
|
||||
|
||||
public function offsetExists( $offset )
|
||||
{
|
||||
$settings = get_option( $this->slug );
|
||||
return isset( $settings[ $offset ] );
|
||||
}
|
||||
|
||||
public function offsetGet( $offset )
|
||||
{
|
||||
$settings = get_option( $this->slug );
|
||||
if ( ! isset( $settings[ $offset ] ) ) {
|
||||
throw new \OutOfBoundsException( "There is no setting '$offset'." );
|
||||
}
|
||||
|
||||
return $settings[ $offset ];
|
||||
}
|
||||
|
||||
public function offsetSet( $offset, $value )
|
||||
{
|
||||
$settings = get_option( $this->slug );
|
||||
if ( ! isset( $settings[ $offset ] ) ) {
|
||||
throw new \OutOfBoundsException( "There is no setting '$offset'." );
|
||||
}
|
||||
|
||||
$settings[ $offset ] = $value;
|
||||
update_option( $this->slug, $settings );
|
||||
}
|
||||
|
||||
public function offsetUnset( $offset )
|
||||
{
|
||||
throw new \BadMethodCallException( 'You cannot unset settings.' );
|
||||
}
|
||||
|
||||
|
||||
public function count()
|
||||
{
|
||||
return count( $this->getDefaults() );
|
||||
}
|
||||
|
||||
|
||||
public function getIterator()
|
||||
{
|
||||
return new \ArrayIterator( get_option( $this->slug ) );
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugins\buena\use\shy-wordpress\src\Shy\WordPress;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Making actions and filters how they should be.
|
||||
*
|
||||
* Default to pass all arguments.
|
||||
*/
|
||||
trait HookableTrait
|
||||
{
|
||||
/**
|
||||
* @param string $action_or_filter
|
||||
* @param string $method
|
||||
* @param int $priority
|
||||
* @param int $acceptedArgs
|
||||
*/
|
||||
protected function addHookMethod( $action_or_filter, $method, $priority = 10, $acceptedArgs = 99 )
|
||||
{
|
||||
add_filter( $action_or_filter, array( $this, $method ), $priority, $acceptedArgs );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $action_or_filter
|
||||
* @param string $method
|
||||
* @param int $priority
|
||||
* @param int $acceptedArgs
|
||||
*/
|
||||
protected function removeHookMethod( $action_or_filter, $method, $priority = 10, $acceptedArgs = 99 )
|
||||
{
|
||||
remove_filter( $action_or_filter, array( $this, $method ), $priority, $acceptedArgs );
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugins\buena\use\shy-wordpress\src\Shy\WordPress;
|
||||
|
||||
|
||||
|
||||
use plugins\buena\use\shy/**
|
||||
* Marker class for WordPress plugins.
|
||||
*/
|
||||
abstract class Plugin
|
||||
{
|
||||
use HookableTrait;
|
||||
}
|
@ -1,383 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugins\buena\use\shy-wordpress\src\Shy\WordPress;
|
||||
|
||||
|
||||
|
||||
use plugins\buena\use\shyuse plugins\buena\use\shy/**
|
||||
* Abstracts common functionality and escaping for the Settings API.
|
||||
*
|
||||
* TODO: Check slug and field names for illegal characters.
|
||||
* TODO: Refactor to not extend but use CompositeOption
|
||||
*/
|
||||
abstract class SettingsPage extends CompositeOption
|
||||
{
|
||||
use HookableTrait;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $capability;
|
||||
|
||||
|
||||
/**
|
||||
* Slug (file name) of the parent menu entry.
|
||||
*
|
||||
* @see add_submenu_page() for suggestions.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
protected function getParentSlug()
|
||||
{
|
||||
return 'options-general.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Title for this setting page.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function getPageTitle();
|
||||
|
||||
/**
|
||||
* String to show in the menu entry.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getMenuTitle()
|
||||
{
|
||||
return $this->getPageTitle();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $slug Page slug
|
||||
* @param string $capability Required capability to view
|
||||
*/
|
||||
protected function __construct( $slug, $capability = 'manage_options' )
|
||||
{
|
||||
parent::__construct( $slug );
|
||||
|
||||
$this->capability = (string) $capability;
|
||||
|
||||
$this->addHookMethod( 'admin_menu', 'registerPage' );
|
||||
$this->addHookMethod( 'admin_init', 'registerSettings' );
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register our options page.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerPage()
|
||||
{
|
||||
add_submenu_page(
|
||||
$this->getParentSlug(),
|
||||
$this->getPageTitle(),
|
||||
$this->getMenuTitle(),
|
||||
$this->capability,
|
||||
$this->slug,
|
||||
array( $this, 'renderPage' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the actual settings.
|
||||
* Override and use addSection() and add*Field() methods.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function registerSettings()
|
||||
{
|
||||
register_setting(
|
||||
$this->slug,
|
||||
$this->slug,
|
||||
array( $this, 'sanitizeOptions' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize option values after form submission.
|
||||
*
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
abstract public function sanitizeOptions( array $options );
|
||||
|
||||
|
||||
/**
|
||||
* Section to add fields to.
|
||||
*
|
||||
* Parameter default from add_settings_field().
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $currentSection = 'default';
|
||||
|
||||
/**
|
||||
* Add a new section and return its generated name.
|
||||
*
|
||||
* @param string $title optional, can be empty
|
||||
* @param string $name optional, will be generated if empty
|
||||
* @return string
|
||||
*/
|
||||
protected function addSection( $title = '', $name = '' )
|
||||
{
|
||||
$name = (string) $name;
|
||||
if ( ! strlen( $name ) ) {
|
||||
$name = $this->slug . '-section' . ( count( $this->getSections() ) + 1 );
|
||||
}
|
||||
|
||||
add_settings_section(
|
||||
$name,
|
||||
esc_html( $title ),
|
||||
array( $this, 'renderSectionTeaser' ),
|
||||
$this->slug
|
||||
);
|
||||
|
||||
return $this->currentSection = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback before output of section fields.
|
||||
*
|
||||
* Teasers must escape their output themselves.
|
||||
*
|
||||
* @param array $section {
|
||||
* @type string $id
|
||||
* @type string $title
|
||||
* @type callable $callback
|
||||
* }
|
||||
*/
|
||||
public function renderSectionTeaser( array $section )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all known section names on this page.
|
||||
*
|
||||
* @global $wp_settings_fields
|
||||
* @return array<string>
|
||||
*/
|
||||
public function getSections()
|
||||
{
|
||||
global $wp_settings_fields;
|
||||
|
||||
if ( ! isset( $wp_settings_fields[ $this->slug ] ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
return array_keys( $wp_settings_fields[ $this->slug ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @global $wp_settings_fields
|
||||
* @param string $section
|
||||
* @return array<string, array {
|
||||
* @type string $id
|
||||
* @type string $title
|
||||
* @type callable $callback
|
||||
* @type array $args
|
||||
* }>
|
||||
*/
|
||||
public function getFieldsForSection( $section )
|
||||
{
|
||||
global $wp_settings_fields;
|
||||
|
||||
return $wp_settings_fields[ $this->slug ][ $section ];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom field to this setting page.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $label
|
||||
* @param callable $callback
|
||||
* @param array $args
|
||||
*/
|
||||
protected function addField( $name, $label, $callback, $args = array() )
|
||||
{
|
||||
if ( ! is_callable( $callback ) ) {
|
||||
throw new \InvalidArgumentException( 'Parameter $callback must be callable.' );
|
||||
}
|
||||
|
||||
add_settings_field(
|
||||
$name,
|
||||
esc_html( $label ),
|
||||
$callback,
|
||||
$this->slug,
|
||||
$this->currentSection,
|
||||
$args
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a text field to this settings page.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $label
|
||||
* @param array $args
|
||||
* @param string $callback
|
||||
*/
|
||||
protected function addTextField( $name, $label, $args = array(), $callback = '' )
|
||||
{
|
||||
if ( ! $callback || ! is_callable( $callback ) ) {
|
||||
$callback = array( $this, 'renderTextField' );
|
||||
}
|
||||
|
||||
$this->addField(
|
||||
$name,
|
||||
$label,
|
||||
$callback,
|
||||
$args + array(
|
||||
'label_for' => $this->slug . '-' . $name,
|
||||
'name' => $name,
|
||||
'attr' => array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param string $label
|
||||
* @param string $caption
|
||||
* @param array $args
|
||||
* @param callable $callback
|
||||
*/
|
||||
protected function addCheckboxField( $name, $label, $caption, $args = array(), $callback = '' )
|
||||
{
|
||||
if ( ! $callback || ! is_callable( $callback ) ) {
|
||||
$callback = array( $this, 'renderCheckboxField' );
|
||||
}
|
||||
|
||||
$this->addField(
|
||||
$name,
|
||||
$label,
|
||||
$callback,
|
||||
$args + array(
|
||||
'label_for' => $this->slug . '-' . $name,
|
||||
'name' => $name,
|
||||
'caption' => $caption,
|
||||
'attr' => array(),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an error.
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $message
|
||||
*/
|
||||
protected function addError( $code, $message )
|
||||
{
|
||||
add_settings_error( $this->slug, $code, $message );
|
||||
}
|
||||
|
||||
/**
|
||||
* Errors for this setting.
|
||||
*
|
||||
* @return array {
|
||||
* @type string $setting
|
||||
* @type string $code
|
||||
* @type string $message
|
||||
* @type string $type 'error'
|
||||
* }
|
||||
*/
|
||||
public function getErrors()
|
||||
{
|
||||
return get_settings_errors( $this->slug );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a setting as text field.
|
||||
*
|
||||
* @param array $args {
|
||||
* @type string $name
|
||||
* @type string $label_for
|
||||
* @type array $attr
|
||||
* }
|
||||
*/
|
||||
public function renderTextField( array $args )
|
||||
{
|
||||
$name = $args['name'];
|
||||
|
||||
$this->renderInputTag( array(
|
||||
'type' => 'text',
|
||||
'id' => $args['label_for'],
|
||||
'class' => 'regular-text',
|
||||
'name' => $this->slug . '[' . $name . ']',
|
||||
'value' => $this[ $name ],
|
||||
) + $args['attr'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a setting as checkbox.
|
||||
*
|
||||
* @param array $args {
|
||||
* @type string $caption
|
||||
* @type string $name
|
||||
* @type string $label_for
|
||||
* @type array $attr
|
||||
* }
|
||||
*/
|
||||
public function renderCheckboxField( array $args )
|
||||
{
|
||||
$name = $args['name'];
|
||||
|
||||
echo '<label>';
|
||||
$this->renderInputTag( array(
|
||||
'type' => 'checkbox',
|
||||
'id' => isset( $args['label_for'] ) ? $args['label_for'] : null,
|
||||
'name' => $this->slug . '[' . $name . ']',
|
||||
'value' => '1',
|
||||
'checked' => $this[ $name ] ? 'checked' : null,
|
||||
) + $args['attr'] );
|
||||
echo ' ' . esc_html( $args['caption'] ) . '</label>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output an input tag with given HTML attributes.
|
||||
*
|
||||
* @param array $attr
|
||||
*/
|
||||
protected function renderInputTag( array $attr )
|
||||
{
|
||||
echo '<input';
|
||||
foreach ( $attr as $k => $v ) {
|
||||
if ( null !== $v ) {
|
||||
printf( ' %s="%s"', $k, esc_attr( $v ) );
|
||||
}
|
||||
}
|
||||
echo ' />';
|
||||
}
|
||||
|
||||
/**
|
||||
* Output settings page.
|
||||
*/
|
||||
public function renderPage()
|
||||
{
|
||||
if ( ! current_user_can( $this->capability ) ) {
|
||||
wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2><?php echo esc_html( $this->getPageTitle() ); ?></h2>
|
||||
<form action="options.php" method="post">
|
||||
<?php settings_errors( 'general' ); // “Settings saved.” message ?>
|
||||
<?php settings_fields( $this->slug ); ?>
|
||||
<?php do_settings_sections( $this->slug ); ?>
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugins\buena\use\shy-wordpress\src\Shy\WordPress;
|
||||
|
||||
|
||||
|
||||
use plugins\buena\use\shyabstract class Theme extends Plugin
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$GLOBALS['content_width'] = $this->getContentWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
abstract public function getContentWidth();
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Try to load a Shy WordPress class.
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
function shy_wordpress_autoloader( $name )
|
||||
{
|
||||
if ( substr( $name, 0, 14 ) !== 'Shy\\WordPress\\' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$name = __DIR__ . '/' . str_replace( '\\', DIRECTORY_SEPARATOR, $name ) . '.php';
|
||||
|
||||
return is_file( $name ) && include( $name );
|
||||
}
|
||||
|
||||
spl_autoload_register( 'shy_wordpress_autoloader' );
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugins\buena\use\shy-wordpress\tests\Shy\WordPress\Tests;
|
||||
|
||||
use wordpress\src\Shy\WordPress\HookableTrait;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Check that HookableTrait actually works.
|
||||
*
|
||||
* @author Philipp Cordes <pc@irgendware.net>
|
||||
*/
|
||||
class HookableTraitTest extends \WP_UnitTestCase
|
||||
{
|
||||
use HookableTrait;
|
||||
|
||||
|
||||
public function actionMethod()
|
||||
{
|
||||
}
|
||||
|
||||
public function testWorksAsAction()
|
||||
{
|
||||
$this->addHookMethod( 'shywp_test_action', 'actionMethod' );
|
||||
$this->assertTrue( has_action( 'shywp_test_action' ), 'Registering an action via addHookMethod() worked.' );
|
||||
}
|
||||
|
||||
|
||||
public function filterMethod( $value )
|
||||
{
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function testWorksAsFilter()
|
||||
{
|
||||
$this->addHookMethod( 'shywp_test_filter', 'filterMethod' );
|
||||
$this->assertTrue( has_filter( 'shywp_test_filter' ), 'Registering a filter via addHookMethod() worked.' );
|
||||
}
|
||||
}
|
@ -1,181 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace plugins\buena\use\shy-wordpress\tests\Shy\WordPress\Tests;
|
||||
|
||||
use wordpress\src\Shy\WordPress\SettingsPage;
|
||||
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
||||
use PHPUnit_Framework_MockObject_Builder_InvocationMocker as BuilderInvocationMocker;
|
||||
|
||||
|
||||
|
||||
class SettingsPageTest extends \WP_UnitTestCase
|
||||
{
|
||||
/**
|
||||
* Mock a SettingsPage.
|
||||
*
|
||||
* @param string|null $slug
|
||||
* @param string $capability
|
||||
*
|
||||
* @return wordpress\src\Shy\WordPress\SettingsPage|MockObject {
|
||||
* @method BuilderInvocationMocker method(string)
|
||||
* }
|
||||
*/
|
||||
protected function mockSettingsPage( $slug = null, $capability = 'manage_options' )
|
||||
{
|
||||
$builder = $this->getMockBuilder( 'plugins\buena\use\shy-wordpress\src\Shy\WordPress\SettingsPage' )
|
||||
->enableProxyingToOriginalMethods();
|
||||
|
||||
if ( null === $slug ) {
|
||||
$builder->disableOriginalConstructor();
|
||||
} else {
|
||||
$builder->setConstructorArgs( array( $slug, $capability ) );
|
||||
}
|
||||
|
||||
return $builder->getMock();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test reading defaults from the settings page.
|
||||
*
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::__construct()
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::getDefaults()
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::offsetExists()
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::offsetGet()
|
||||
* @expectedException OutOfBoundsException
|
||||
*/
|
||||
public function testReading()
|
||||
{
|
||||
$slug = 'shywp_settingspage_test_slug_reading';
|
||||
$defaults = array( 'foo' => 'bar' );
|
||||
|
||||
$page = $this->mockSettingsPage( $slug );
|
||||
$page->method( 'getDefaults' )->willReturn( $defaults );
|
||||
|
||||
$this->assertEquals( $defaults, get_option( $slug ) );
|
||||
|
||||
$this->assertArrayHasKey( 'foo', $page );
|
||||
$this->assertEquals( $defaults['foo'], $page['foo'] );
|
||||
|
||||
$this->assertArrayNotHasKey( 'baz', $page );
|
||||
$page['baz'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test writing to the settings page.
|
||||
*
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::offsetSet()
|
||||
* @expectedException OutOfBoundsException
|
||||
*/
|
||||
public function testWriting()
|
||||
{
|
||||
$slug = 'shywp_settingspage_test_slug_writing';
|
||||
$defaults = array( 'foo' => 'bar' );
|
||||
|
||||
$page = $this->mockSettingsPage( $slug );
|
||||
$page->method( 'getDefaults' )->willReturn( $defaults );
|
||||
|
||||
$page['foo'] = 'foo';
|
||||
$this->assertEquals( 'foo', $page['foo'] );
|
||||
$page['baz'] = '123';
|
||||
}
|
||||
|
||||
/**
|
||||
* Fail to remove a setting.
|
||||
*
|
||||
* @covers SettingPage::offsetUnset()
|
||||
* @expectedException BadMethodCallException
|
||||
*/
|
||||
public function testRemoving()
|
||||
{
|
||||
$slug = 'shywp_settingspage_test_slug_removing';
|
||||
$defaults = array();
|
||||
|
||||
$page = $this->mockSettingsPage( $slug );
|
||||
$page->method( 'getDefaults' )->willReturn( $defaults );
|
||||
|
||||
unset( $page['baz'] );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test whether the settings page can be showed.
|
||||
*
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::__construct()
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::getParentSlug()
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::getPageTitle()
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::getMenuTitle()
|
||||
*/
|
||||
public function testRegisterPage()
|
||||
{
|
||||
$this->expectOutputRegex( '/<page&title>/' );
|
||||
|
||||
$slug = 'shywp_settingspage_test_slug_registerpage';
|
||||
|
||||
$page = $this->mockSettingsPage( $slug );
|
||||
$page->method( 'getParentSlug' )->willReturn( 'index.php' );
|
||||
$page->method( 'getPageTitle' )->willReturn( '<page&title>' );
|
||||
$page->method( 'getMenuTitle' )->willReturn( '<menu&title>' );
|
||||
|
||||
$page->expects( $this->once() )->method( 'registerPage' )->with();
|
||||
$page->expects( $this->once() )->method( 'registerSettings' )->with();
|
||||
|
||||
// FIXME: Simulate display of backend.
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers wordpress\src\Shy\WordPress\SettingsPage::sanitizeOptions()
|
||||
*/
|
||||
public function testSanitize()
|
||||
{
|
||||
$slug = 'shywp_settingspage_test_slug_sanitize';
|
||||
|
||||
$page = $this->mockSettingsPage( $slug );
|
||||
$page->method( 'sanitizeOptions' )->will( $this->returnArgument( 0 ) );
|
||||
$page->expects( $this->atLeastOnce() )->method( 'sanitizeOptions' );
|
||||
|
||||
$this->markTestIncomplete();
|
||||
// FIXME: Simulate form submission
|
||||
}
|
||||
|
||||
public function testRenderTextField()
|
||||
{
|
||||
$this->expectOutputRegex( '/^<input type="text"/' );
|
||||
|
||||
$page = $this->mockSettingsPage();
|
||||
$page->renderTextField( array(
|
||||
'label_for' => 'foo',
|
||||
'name' => 'bar',
|
||||
) );
|
||||
}
|
||||
|
||||
public function testRenderCheckboxField()
|
||||
{
|
||||
$this->expectOutputRegex( '/^<label><input type="checkbox"/' );
|
||||
|
||||
$page = $this->mockSettingsPage();
|
||||
$page->renderCheckboxField( array(
|
||||
'label_for' => 'foo',
|
||||
'name' => 'bar',
|
||||
'caption' => 'baz',
|
||||
) );
|
||||
}
|
||||
|
||||
public function testRenderPage()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$this->expectOutputRegex( '/<form action="options.php" method="post">.*<3&>.*cryptic_teaser.*</form>/' );
|
||||
|
||||
$slug = 'shywp_settingspage_test_slug_renderpage';
|
||||
|
||||
$page = $this->mockSettingsPage( $slug, 'read' );
|
||||
$page->method( 'getPageTitle' )->willReturn( '<3&>' );
|
||||
$page->method( 'renderSectionTeaser' )->will( $this->returnCallback( function () use ( $teaser ) {
|
||||
echo 'cryptic_teaser';
|
||||
} ) );
|
||||
|
||||
// FIXME: Simulate view of the settings page
|
||||
$page->renderPage();
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Try to load a Shy WordPress test class.
|
||||
*
|
||||
* @param string $name
|
||||
* @return boolean
|
||||
*/
|
||||
function shy_wordpress_tests_autoloader( $name )
|
||||
{
|
||||
if ( substr( $name, 0, 20 ) !== 'Shy\\WordPress\\Tests\\' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$name = __DIR__ . '/' . str_replace( '\\', DIRECTORY_SEPARATOR, $name ) . '.php';
|
||||
|
||||
return is_file( $name ) && include( $name );
|
||||
}
|
||||
|
||||
spl_autoload_register( 'shy_wordpress_tests_autoloader' );
|
@ -1,14 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPUnit bootstrap file
|
||||
*
|
||||
* Variant of the one from github.com/tierra/wordpress-plugins-tests
|
||||
*/
|
||||
|
||||
require_once '../src/autoloader.php';
|
||||
require_once 'autoloader.php';
|
||||
|
||||
|
||||
|
||||
require_once ( getenv( 'WP_DEVELOP_DIR' ) ?: '../../../..' )
|
||||
. '/tests/phpunit/includes/bootstrap.php';
|
Loading…
Reference in New Issue
Block a user