Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions app/Themes/Apiary/Providers/AssetServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Themes\Apiary\Providers;

use Illuminate\Support\ServiceProvider;
use Pollora\Support\Facades\Asset;
use Pollora\Support\Facades\Filter;

class AssetServiceProvider extends ServiceProvider
{
protected $theme;

/**
* Theme Assets
*/
public function register()
{
}

public function boot()
{
Asset::add('default/script', 'assets/app.js')
->toFrontend()
->useVite();

Filter::add('woocommerce_enqueue_styles', function (array $enqueueStyles) {
// Remove the default WooCommerce styles, layout ands the smallscreen optimisation
unset($enqueueStyles['woocommerce-general'], $enqueueStyles['woocommerce-layout'], $enqueueStyles['woocommerce-smallscreen']);
return $enqueueStyles;
});
}
}
23 changes: 23 additions & 0 deletions app/Themes/Apiary/Providers/ThemeComponentProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Themes\Apiary\Providers;

use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;

class ThemeComponentProvider extends ServiceProvider
{
public function boot()
{
$this->bootBladeComponents();
}

protected function bootBladeComponents(): self
{
if (version_compare($this->app->version(), '8.0.0', '>=')) {
Blade::componentNamespace('App\Themes\Apiary\\View\\Components', 'theme');
}

return $this;
}
}
47 changes: 47 additions & 0 deletions app/Themes/Apiary/Providers/WordPress/Formatting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Themes\Apiary\Providers\WordPress;

use Illuminate\Support\ServiceProvider;
use Pollora\Support\Facades\Filter;

class Formatting extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Filter::add('sanitize_html_class', [$this, 'sanitizeHtmlClasses'], 99, 3);
}

/**
* Fix for Tailwind CSS Classes
*
* @param string $class
*/
public function sanitizeHtmlClasses(string $sanitized, $class, string $fallback): string
{
// Strip out any %-encoded octets.
$sanitized = preg_replace('|%[a-fA-F0-9][a-fA-F0-9]|', '', $class);

// Limit to A-Z, a-z, :, 0-9, '_', '-'.
$sanitized = preg_replace('/[^A-Za-z0-9\:_-]/', '', $sanitized);

if ('' === $sanitized && $fallback) {
return sanitize_html_class($fallback);
}
/**
* Filters a sanitized HTML class string.
*
* @param string $sanitized The sanitized HTML class.
* @param string $class HTML class before sanitization.
* @param string $fallback The fallback string.
*
* @since 2.8.0
*/
return $sanitized;
}
}
137 changes: 137 additions & 0 deletions app/Themes/Apiary/Walkers/MenuPrimary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

declare(strict_types=1);

namespace App\Themes\Apiary\Walkers;

class MenuPrimary extends \Walker_Nav_Menu
{
/**
* Store the current item for later use.
*/
protected $currentItem = null;

/**
* Starts the element output.
*/
public function start_el(&$output, $item, $depth = 0, $args = [], $id = 0): void
{
if ($depth === 0) {
$this->currentItem = $item;
}

if (! is_array($item->classes)) {
$item->classes = [$item->classes];
}

$hasChildren = in_array('menu-item-has-children', $item->classes);

if ($hasChildren && $depth === 0) {
$output .= $this->createDropdownParent($item, $args);
} else {
$output .= $this->createMenuItem($item, $depth, $args);
}
}

/**
* Ends the element output.
*/
public function end_el(&$output, $item, $depth = 0, $args = [], $id = 0): void
{
if (in_array('menu-item-has-children', $item->classes) && $depth === 0) {
$output .= '</div></div>';
}
}

/**
* Starts the list wrapper.
*/
public function start_lvl(&$output, $depth = 0, $args = []): void
{
if ($depth === 0) {
$output .= '<div x-show="open"
x-transition:enter="transition ease-out duration-100"
x-transition:enter-start="transform opacity-0 scale-95"
x-transition:enter-end="transform opacity-100 scale-100"
x-transition:leave="transition ease-in duration-75"
x-transition:leave-start="transform opacity-100 scale-100"
x-transition:leave-end="transform opacity-0 scale-95"
class="md:absolute right-0 w-full mt-2 origin-top-right rounded-md md:shadow-lg md:w-48 z-30">
<div class="md:px-2 md:py-2 bg-white rounded-md md:shadow-sm divide-y divide-gray-100"><div>';
}
}

/**
* Ends the list wrapper.
*/
public function end_lvl(&$output, $depth = 0, $args = []): void
{
if ($depth === 0) {
$parent_item = $this->currentItem;
$output .= '</div>';
$output .= sprintf(
'<a href="%s" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white">
%s %s
</a>',
esc_url($parent_item->url),
__('Access to'),
$parent_item->title
);
$output .= '</div>';
}
}

/**
* Creates a dropdown parent element.
*/
protected function createDropdownParent($item, $args): string
{
$classes = empty($item->classes) ? [] : (array) $item->classes;
$classes[] = 'relative';

return sprintf(
'<div @click.away="open = false" class="%s" x-data="{ open: false }">
<button @click="open = !open" class="flex flex-row items-center w-full px-4 py-2 mt-2 text-sm font-semibold text-left bg-transparent rounded-lg md:w-auto md:inline md:mt-0 md:ml-4 hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-hidden focus:shadow-outline">
<span>%s</span>
<svg fill="currentColor" viewBox="0 0 20 20" :class="{\'rotate-180\': open, \'rotate-0\': !open}" class="inline w-4 h-4 mt-1 ml-1 transition-transform duration-200 transform md:-mt-1">
<path fill-rule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clip-rule="evenodd"></path>
</svg>
</button>',
implode(' ', $classes),
$item->title
);
}

/**
* Creates a regular menu item.
*/
protected function createMenuItem($item, $depth, $args): string
{
$classes = empty($item->classes) ? [] : (array) $item->classes;

// Classes de base pour les liens
if ($depth === 0) {
$classes[] = 'px-4 py-2 mt-2 text-sm font-semibold text-gray-900 bg-transparent rounded-lg md:mt-0 md:ml-4 hover:text-gray-900 focus:text-gray-900 hover:bg-gray-200 focus:bg-gray-200 focus:outline-hidden focus:shadow-outline';
} else {
$classes[] = 'block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100 dark:hover:bg-gray-600 dark:text-gray-200 dark:hover:text-white';
}

$atts = [
'href' => !empty($item->url) ? $item->url : '#',
'title' => !empty($item->attr_title) ? $item->attr_title : '',
'target' => !empty($item->target) ? $item->target : '',
'rel' => !empty($item->xfn) ? $item->xfn : '',
'class' => implode(' ', $classes)
];

$attributes = '';
foreach ($atts as $attr => $value) {
if (!empty($value)) {
$value = ('href' === $attr) ? esc_url($value) : esc_attr($value);
$attributes .= ' ' . $attr . '="' . $value . '"';
}
}

return sprintf('<a%s>%s</a>', $attributes, $item->title);
}
}
30 changes: 30 additions & 0 deletions app/Themes/Apiary/inc/helpers/image-helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Themes\Apiary;

/**
* Wrapper for Image Processing Queue function.
*
* @param int $post_id
* @param mixed $size
* @return string Img URL
*/
function get_resized_image_url(int $img_id, $size)
{
// Fallback or check if $size is string (it means size should be already generated)
if (! function_exists('ipq_get_theme_image_url') || is_string($size)) {
return wp_get_attachment_image_url($img_id, $size);
}

return ipq_get_theme_image_url($img_id, $size);
}

/**
* Get image alt attribute
*
* @return string Img ALT
*/
function get_image_alt(int $img_id)
{
return get_post_meta($img_id, '_wp_attachment_image_alt', true);
}
57 changes: 57 additions & 0 deletions app/Themes/Apiary/inc/helpers/post-helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Themes\Apiary;

/**
* Get teaser data in nice array format.
*
* @param int $post_id
* @param string $img_size
* @return array
*/
function get_post_teaser_data($post_id, $img_size = 'thumbnail')
{
if (empty($post_id)) {
$post_id = get_the_id();
}

$img_id = get_post_thumbnail_id($post_id);
$author_id = get_post_field('post_author', $post_id);
$author_name = get_the_author_meta('display_name', $author_id);
$author_url = get_author_posts_url($author_id);

return [
'title' => get_the_title($post_id),
'link' => get_permalink($post_id),
'excerpt' => get_the_excerpt($post_id),
'time' => get_post_time('c', true, $post_id),
'date' => get_the_date('', $post_id),
'author_name' => $author_name,
'author_url' => $author_url,
'img' => [
'url' => get_resized_image_url($img_id, $img_size),
'alt' => get_image_alt($img_id),
],
];
}

/**
* Get single post data in nice array format.
*
* @param int $post_id
* @return array
*/
function get_single_post_data($post_id = 0)
{
if (empty($post_id)) {
$post_id = get_the_id();
}

// We can get and use all teaser data
$data = get_post_teaser_data($post_id, 'medium');

// And add more data
return array_merge($data, [
'content' => apply_filters('the_content', get_post_field('post_content', $post_id, 'raw')),
]);
}
22 changes: 22 additions & 0 deletions app/Themes/Apiary/inc/helpers/wrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

function wrapper_open(string $classes = '', string $tag = 'div', bool $echo = true)
{
$html = "<{$tag} class=\"{$classes}\">";
if ($echo) {
echo $html;
} else {
return $html;
}
}

function wrapper_close(string $tag = 'div', bool $echo = true)
{
$tag = $tag === '' ? 'div' : $tag;
$html = "</{$tag}>";
if ($echo) {
echo $html;
} else {
return $html;
}
}
Loading