From 4bdbddc84dfcc19f5fb6629515ba5275e3d1f0f1 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 28 May 2020 09:35:06 +0200 Subject: [PATCH] adap function php --- web/app/themes/la_mine/.travis.yml | 22 -- web/app/themes/la_mine/LICENSE | 7 - web/app/themes/la_mine/association.php | 2 +- web/app/themes/la_mine/functions.php | 218 ++---------------- web/app/themes/la_mine/inc/function.php | 227 +++++++++++++++---- web/app/themes/la_mine/index.php | 2 +- web/app/themes/la_mine/la_benevole_zone.php | 2 +- web/app/themes/la_mine/la_collecte.php | 4 +- web/app/themes/la_mine/les_projets.php | 2 +- web/app/themes/la_mine/les_temps_forts.php | 2 +- web/app/themes/la_mine/phpunit.xml | 20 -- web/app/themes/la_mine/search.php | 18 -- web/app/themes/la_mine/templates/search.twig | 13 -- web/app/themes/la_mine/templates/single.twig | 2 +- 14 files changed, 207 insertions(+), 334 deletions(-) delete mode 100644 web/app/themes/la_mine/.travis.yml delete mode 100755 web/app/themes/la_mine/LICENSE delete mode 100644 web/app/themes/la_mine/phpunit.xml delete mode 100755 web/app/themes/la_mine/search.php delete mode 100644 web/app/themes/la_mine/templates/search.twig diff --git a/web/app/themes/la_mine/.travis.yml b/web/app/themes/la_mine/.travis.yml deleted file mode 100644 index 0e64c4ac..00000000 --- a/web/app/themes/la_mine/.travis.yml +++ /dev/null @@ -1,22 +0,0 @@ -sudo: false - -dist: xenial - -services: mysql - -language: php - -php: - - 5.6.30 - - 7.3 - -env: - - WP_VERSION=latest WP_MULTISITE=0 - - WP_VERSION=latest WP_MULTISITE=1 - -before_script: - - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION - - composer install - -script: - - vendor/phpunit/phpunit/phpunit diff --git a/web/app/themes/la_mine/LICENSE b/web/app/themes/la_mine/LICENSE deleted file mode 100755 index 0c18744b..00000000 --- a/web/app/themes/la_mine/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (c) 2012-2013 Jared Novack - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/web/app/themes/la_mine/association.php b/web/app/themes/la_mine/association.php index 966b1e7f..51ac3119 100644 --- a/web/app/themes/la_mine/association.php +++ b/web/app/themes/la_mine/association.php @@ -7,4 +7,4 @@ $context = Timber::context(); $timber_post = new Timber\Post(); $context['post'] = $timber_post; -Timber::render( array( 'page-' . $timber_post->post_name . '.twig', 'association.twig' ), $context ); +Timber::render('association.twig', $context ); diff --git a/web/app/themes/la_mine/functions.php b/web/app/themes/la_mine/functions.php index b429b74b..ddf3f022 100644 --- a/web/app/themes/la_mine/functions.php +++ b/web/app/themes/la_mine/functions.php @@ -1,206 +1,32 @@ 'Information', + 'menu_title' => 'Information', + 'menu_slug' => 'information', + 'capability' => 'edit_posts', + 'redirect' => false + )); - acf_add_options_page(array( - 'page_title' => 'Information', - 'menu_title' => 'Information', - 'menu_slug' => 'information', - 'capability' => 'edit_posts', - 'redirect' => false - )); - - acf_add_options_sub_page(array( - 'page_title' => 'Partenaires', - 'menu_title' => 'Partenaires', - 'parent_slug' => 'information', - )); - -} - -add_filter( 'timber_context', 'options_footer' ); - -function options_footer( $context ) { - $context['options'] = get_fields('option'); - return $context; -} - -/** - * This ensures that Timber is loaded and available as a PHP class. - * If not, it gives an error message to help direct developers on where to activate - */ -if ( ! class_exists( 'Timber' ) ) { - - add_action( - 'admin_notices', - function() { - echo '

Timber not activated. Make sure you activate the plugin in ' . esc_url( admin_url( 'plugins.php' ) ) . '

'; - } - ); - - add_filter( - 'template_include', - function( $template ) { - return get_stylesheet_directory() . '/static/no-timber.html'; - } - ); - return; -} - -/** - * Sets the directories (inside your theme) to find .twig files - */ -Timber::$dirname = array( 'templates', 'views' ); - -/** - * By default, Timber does NOT autoescape values. Want to enable Twig's autoescape? - * No prob! Just set this value to true - */ -Timber::$autoescape = false; - - -// REMOVE EDITOR - function remove_editor() { - remove_post_type_support( - 'page', 'editor' - ); - remove_post_type_support( - 'post', 'editor' - ); - - }; - - add_action('admin_init', 'remove_editor'); - -/** - * We're going to configure our theme inside of a subclass of Timber\Site - * You can move this to its own file and include here via php's include("MySite.php") - */ -class StarterSite extends Timber\Site { - /** Add timber support. */ - public function __construct() { - add_action( 'after_setup_theme', array( $this, 'theme_supports' ) ); - add_filter( 'timber/context', array( $this, 'add_to_context' ) ); - add_filter( 'timber/twig', array( $this, 'add_to_twig' ) ); - add_action( 'init', array( $this, 'register_post_types' ) ); - add_action( 'init', array( $this, 'register_taxonomies' ) ); - parent::__construct(); - } - /** This is where you can register custom post types. */ - public function register_post_types() { - - } - /** This is where you can register custom taxonomies. */ - public function register_taxonomies() { + acf_add_options_sub_page(array( + 'page_title' => 'Partenaires', + 'menu_title' => 'Partenaires', + 'parent_slug' => 'information', + )); } - /** This is where you add some context - * - * @param string $context context['this'] Being the Twig's {{ this }}. - */ - public function add_to_context( $context ) { - $context['foo'] = 'bar'; - $context['stuff'] = 'I am a value set in your functions.php file'; - $context['notes'] = 'These values are available everytime you call Timber::context();'; - $context['menu'] = new Timber\Menu(); - $context['site'] = $this; - return $context; + add_filter( 'timber_context', 'options_footer' ); + + function options_footer( $context ) { + $context['options'] = get_fields('option'); + return $context; } - public function theme_supports() { - // Add default posts and comments RSS feed links to head. - add_theme_support( 'automatic-feed-links' ); - - /* - * Let WordPress manage the document title. - * By adding theme support, we declare that this theme does not use a - * hard-coded tag in the document head, and expect WordPress to - * provide it for us. - */ - add_theme_support( 'title-tag' ); - - /* - * Enable support for Post Thumbnails on posts and pages. - * - * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ - */ - add_theme_support( 'post-thumbnails' ); - - /* - * Switch default core markup for search form, comment form, and comments - * to output valid HTML5. - */ - add_theme_support( - 'html5', - array( - 'comment-form', - 'comment-list', - 'gallery', - 'caption', - ) - ); - - /* - * Enable support for Post Formats. - * - * See: https://codex.wordpress.org/Post_Formats - */ - add_theme_support( - 'post-formats', - array( - 'aside', - 'image', - 'video', - 'quote', - 'link', - 'gallery', - 'audio', - ) - ); - - add_theme_support( 'menus' ); - } - - /** This Would return 'foo bar!'. - * - * @param string $text being 'foo', then returned 'foo bar!'. - */ - public function myfoo( $text ) { - $text .= ' bar!'; - return $text; - } - - /** This is where you can add your own functions to twig. - * - * @param string $twig get extension. - */ - public function add_to_twig( $twig ) { - $twig->addExtension( new Twig\Extension\StringLoaderExtension() ); - $twig->addFilter( new Twig\TwigFilter( 'myfoo', array( $this, 'myfoo' ) ) ); - return $twig; - } - -} - -new StarterSite(); + ?> diff --git a/web/app/themes/la_mine/inc/function.php b/web/app/themes/la_mine/inc/function.php index 5ec2a841..002e4d74 100644 --- a/web/app/themes/la_mine/inc/function.php +++ b/web/app/themes/la_mine/inc/function.php @@ -1,54 +1,181 @@ <?php -function wpc_cpt() { +/** + * Timber starter-theme + * https://github.com/timber/starter-theme + * + * @package WordPress + * @subpackage Timber + * @since Timber 0.1 + */ - /* Property */ - $labels = array( - 'name' => _x('Properties', 'Post Type General Name', 'la_mine'), - 'singular_name' => _x('Property', 'Post Type Singular Name', 'la_mine'), - 'menu_name' => __('Properties', 'la_mine'), - 'name_admin_bar' => __('Properties', 'la_mine'), - 'parent_item_colon' => __('Parent Item:', 'la_mine'), - 'all_items' => __('All Items', 'la_mine'), - 'add_new_item' => __('Add New Item', 'la_mine'), - 'add_new' => __('Add New', 'la_mine'), - 'new_item' => __('New Item', 'la_mine' ), - 'edit_item' => __('Edit Item', 'la_mine'), - 'update_item' => __('Update Item', 'la_mine'), - 'view_item' => __('View Item', 'la_mine'), - 'search_items' => __('Search Item', 'la_mine'), - 'not_found' => __('Not found', 'la_mine'), - 'not_found_in_trash' => __('Not found in Trash', 'la_mine'), - ); - $rewrite = array( - 'slug' => _x('property', 'property', 'la_mine'), - 'with_front' => true, - 'pages' => true, - 'feeds' => false, - ); - $args = array( - 'label' => __('property', 'la_mine'), - 'description' => __('Properties', 'la_mine'), - 'labels' => $labels, - 'supports' => array('title', 'editor', 'thumbnail', 'comments', 'revisions', 'custom-fields'), - 'taxonomies' => array('property_type'), - 'hierarchical' => false, - 'public' => true, - 'show_ui' => true, - 'show_in_menu' => true, - 'menu_position' => 5, - 'menu_icon' => 'dashicons-admin-home', - 'show_in_admin_bar' => true, - 'show_in_nav_menus' => true, - 'can_export' => true, - 'has_archive' => false, - 'exclude_from_search' => false, - 'publicly_queryable' => true, - 'query_var' => 'property', - 'rewrite' => $rewrite, - 'capability_type' => 'page', - ); - register_post_type('property', $args); +/** + * If you are installing Timber as a Composer dependency in your theme, you'll need this block + * to load your dependencies and initialize Timber. If you are using Timber via the WordPress.org + * plug-in, you can safely delete this block. + */ + +$composer_autoload = __DIR__ . '/vendor/autoload.php'; +if ( file_exists( $composer_autoload ) ) { + require_once $composer_autoload; + $timber = new Timber\Timber(); } -add_action('init', 'wpc_cpt', 10); -?> +/** + * This ensures that Timber is loaded and available as a PHP class. + * If not, it gives an error message to help direct developers on where to activate + */ +if ( ! class_exists( 'Timber' ) ) { + + add_action( + 'admin_notices', + function() { + echo '<div class="error"><p>Timber not activated. Make sure you activate the plugin in <a href="' . esc_url( admin_url( 'plugins.php#timber' ) ) . '">' . esc_url( admin_url( 'plugins.php' ) ) . '</a></p></div>'; + } + ); + + add_filter( + 'template_include', + function( $template ) { + return get_stylesheet_directory() . '/static/no-timber.html'; + } + ); + return; +} + +/** + * Sets the directories (inside your theme) to find .twig files + */ +Timber::$dirname = array( 'templates', 'views' ); + +/** + * By default, Timber does NOT autoescape values. Want to enable Twig's autoescape? + * No prob! Just set this value to true + */ +Timber::$autoescape = false; + + +// REMOVE EDITOR + function remove_editor() { + remove_post_type_support( + 'page', 'editor' + ); + remove_post_type_support( + 'post', 'editor' + ); + + }; + + add_action('admin_init', 'remove_editor'); + +/** + * We're going to configure our theme inside of a subclass of Timber\Site + * You can move this to its own file and include here via php's include("MySite.php") + */ +class StarterSite extends Timber\Site { + /** Add timber support. */ + public function __construct() { + add_action( 'after_setup_theme', array( $this, 'theme_supports' ) ); + add_filter( 'timber/context', array( $this, 'add_to_context' ) ); + add_filter( 'timber/twig', array( $this, 'add_to_twig' ) ); + add_action( 'init', array( $this, 'register_post_types' ) ); + add_action( 'init', array( $this, 'register_taxonomies' ) ); + parent::__construct(); + } + /** This is where you can register custom post types. */ + public function register_post_types() { + + } + /** This is where you can register custom taxonomies. */ + public function register_taxonomies() { + + } + + /** This is where you add some context + * + * @param string $context context['this'] Being the Twig's {{ this }}. + */ + public function add_to_context( $context ) { + $context['foo'] = 'bar'; + $context['stuff'] = 'I am a value set in your functions.php file'; + $context['notes'] = 'These values are available everytime you call Timber::context();'; + $context['menu'] = new Timber\Menu(); + $context['site'] = $this; + return $context; + } + + public function theme_supports() { + // Add default posts and comments RSS feed links to head. + add_theme_support( 'automatic-feed-links' ); + + /* + * Let WordPress manage the document title. + * By adding theme support, we declare that this theme does not use a + * hard-coded <title> tag in the document head, and expect WordPress to + * provide it for us. + */ + add_theme_support( 'title-tag' ); + + /* + * Enable support for Post Thumbnails on posts and pages. + * + * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ + */ + add_theme_support( 'post-thumbnails' ); + + /* + * Switch default core markup for search form, comment form, and comments + * to output valid HTML5. + */ + add_theme_support( + 'html5', + array( + 'comment-form', + 'comment-list', + 'gallery', + 'caption', + ) + ); + + /* + * Enable support for Post Formats. + * + * See: https://codex.wordpress.org/Post_Formats + */ + add_theme_support( + 'post-formats', + array( + 'aside', + 'image', + 'video', + 'quote', + 'link', + 'gallery', + 'audio', + ) + ); + + add_theme_support( 'menus' ); + } + + /** This Would return 'foo bar!'. + * + * @param string $text being 'foo', then returned 'foo bar!'. + */ + public function myfoo( $text ) { + $text .= ' bar!'; + return $text; + } + + /** This is where you can add your own functions to twig. + * + * @param string $twig get extension. + */ + public function add_to_twig( $twig ) { + $twig->addExtension( new Twig\Extension\StringLoaderExtension() ); + $twig->addFilter( new Twig\TwigFilter( 'myfoo', array( $this, 'myfoo' ) ) ); + return $twig; + } + +} + +new StarterSite(); diff --git a/web/app/themes/la_mine/index.php b/web/app/themes/la_mine/index.php index 36c73b8e..e42e997f 100755 --- a/web/app/themes/la_mine/index.php +++ b/web/app/themes/la_mine/index.php @@ -18,6 +18,6 @@ $context['posts'] = new Timber\PostQuery(); $templates = array( 'base.twig' ); if ( is_home() ) { - array_unshift( $templates, 'front-page.twig', 'accueil.twig' ); + array_unshift(' accueil.twig' ); } Timber::render( $templates, $context ); diff --git a/web/app/themes/la_mine/la_benevole_zone.php b/web/app/themes/la_mine/la_benevole_zone.php index db899c5a..049b2cd5 100644 --- a/web/app/themes/la_mine/la_benevole_zone.php +++ b/web/app/themes/la_mine/la_benevole_zone.php @@ -9,4 +9,4 @@ $context = Timber::context(); $timber_post = new Timber\Post(); $context['post'] = $timber_post; -Timber::render( array( 'page-' . $timber_post->post_name . '.twig', 'la_benevole_zone.twig' ), $context ); +Timber::render('la_benevole_zone.twig', $context ); diff --git a/web/app/themes/la_mine/la_collecte.php b/web/app/themes/la_mine/la_collecte.php index 72d0b4c5..beb050f7 100644 --- a/web/app/themes/la_mine/la_collecte.php +++ b/web/app/themes/la_mine/la_collecte.php @@ -1,10 +1,10 @@ <?php /** - * template name: La collecte + * template name: La collecte */ $context = Timber::context(); $timber_post = new Timber\Post(); $context['post'] = $timber_post; -Timber::render( array( 'page-' . $timber_post->post_name . '.twig', 'la_collecte.twig' ), $context ); +Timber::render( 'la_collecte.twig', $context ); diff --git a/web/app/themes/la_mine/les_projets.php b/web/app/themes/la_mine/les_projets.php index 1f55324c..3071d482 100644 --- a/web/app/themes/la_mine/les_projets.php +++ b/web/app/themes/la_mine/les_projets.php @@ -9,4 +9,4 @@ $timber_post = new Timber\Post(); $context['post'] = $timber_post; -Timber::render( array( 'les_projets.twig' ), $context ); +Timber::render( 'les_projets.twig', $context ); diff --git a/web/app/themes/la_mine/les_temps_forts.php b/web/app/themes/la_mine/les_temps_forts.php index 75aaa56f..97f86d2b 100755 --- a/web/app/themes/la_mine/les_temps_forts.php +++ b/web/app/themes/la_mine/les_temps_forts.php @@ -8,4 +8,4 @@ $context = Timber::context(); $timber_post = new Timber\Post(); $context['post'] = $timber_post; -Timber::render( array( 'page-' . $timber_post->post_name . '.twig', 'les_temps_forts.twig' ), $context ); +Timber::render( 'les_temps_forts.twig', $context ); diff --git a/web/app/themes/la_mine/phpunit.xml b/web/app/themes/la_mine/phpunit.xml deleted file mode 100644 index e7f21fc5..00000000 --- a/web/app/themes/la_mine/phpunit.xml +++ /dev/null @@ -1,20 +0,0 @@ -<phpunit - bootstrap="tests/bootstrap.php" - backupGlobals="false" - colors="true" - convertErrorsToExceptions="true" - convertNoticesToExceptions="true" - convertWarningsToExceptions="true" - > - <testsuites> - <testsuite> - <directory prefix="test-" suffix=".php">./tests/</directory> - </testsuite> - <!-- The suite below HAS to be last to run, - as it includes a test that sets some const and would contaminate - the other tests as well. --> - <testsuite> - <directory prefix="testX-" suffix=".php">./tests/</directory> - </testsuite> - </testsuites> -</phpunit> diff --git a/web/app/themes/la_mine/search.php b/web/app/themes/la_mine/search.php deleted file mode 100755 index 600a6abb..00000000 --- a/web/app/themes/la_mine/search.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php -/** - * Search results page - * - * Methods for TimberHelper can be found in the /lib sub-directory - * - * @package WordPress - * @subpackage Timber - * @since Timber 0.1 - */ - -$templates = array( 'search.twig', 'archive.twig', 'index.twig' ); - -$context = Timber::context(); -$context['title'] = 'Search results for ' . get_search_query(); -$context['posts'] = new Timber\PostQuery(); - -Timber::render( $templates, $context ); diff --git a/web/app/themes/la_mine/templates/search.twig b/web/app/themes/la_mine/templates/search.twig deleted file mode 100644 index 31fd42fc..00000000 --- a/web/app/themes/la_mine/templates/search.twig +++ /dev/null @@ -1,13 +0,0 @@ -{# see `archive.twig` for an alternative strategy of extending templates #} -{% extends "base.twig" %} - -{% block content %} - {# see `base.twig:27` for where this block's content will be inserted #} - <div class="content-wrapper"> - {% for post in posts %} - {% include ['tease-'~post.post_type~'.twig', 'tease.twig'] %} - {% endfor %} - - {% include 'partial/pagination.twig' with { pagination: posts.pagination({show_all: false, mid_size: 3, end_size: 2}) } %} - </div> -{% endblock %} diff --git a/web/app/themes/la_mine/templates/single.twig b/web/app/themes/la_mine/templates/single.twig index dc3f05e6..4cad633e 100644 --- a/web/app/themes/la_mine/templates/single.twig +++ b/web/app/themes/la_mine/templates/single.twig @@ -21,5 +21,5 @@ </section> </article> - </div><!-- /content-wrapper --> + </div> {% endblock %}