Skip to content
Merged
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
58 changes: 58 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Tests

on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]

jobs:
tests:
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
php: [8.2, 8.3, 8.4]

name: PHP ${{ matrix.php }}

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, intl, pdo_sqlite
coverage: none
ini-values: memory_limit=512M

- name: Install October CMS
run: |
composer create-project october/october october --no-interaction --no-progress

- name: Configure environment
run: |
cd october
mkdir -p database && touch database/database.sqlite
sed -i 's/DB_CONNECTION=.*/DB_CONNECTION=sqlite/' .env
sed -i 's|DB_DATABASE=.*|DB_DATABASE=database/database.sqlite|' .env

- name: Migrate core tables
run: |
cd october
php artisan october:migrate --no-interaction

- name: Checkout plugin
uses: actions/checkout@v4
with:
path: october/plugins/rainlab/blog

- name: Migrate plugin
run: |
cd october
php artisan october:migrate --no-interaction

- name: Run tests
run: |
cd october
php vendor/bin/phpunit --configuration plugins/rainlab/blog/phpunit.xml
185 changes: 92 additions & 93 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -1,180 +1,179 @@
<?php namespace RainLab\Blog;

use Event;
use Backend;
use Controller;
use RainLab\Blog\Models\Post;
use System\Classes\PluginBase;
use RainLab\Blog\Classes\TagProcessor;
use RainLab\Blog\Models\Post;
use RainLab\Blog\Models\Category;
use Event;

/**
* Plugin registration for Blog
*/
class Plugin extends PluginBase
{
/**
* pluginDetails
*/
public function pluginDetails()
{
return [
'name' => 'rainlab.blog::lang.plugin.name',
'description' => 'rainlab.blog::lang.plugin.description',
'author' => 'Alexey Bobkov, Samuel Georges',
'icon' => 'icon-pencil',
'homepage' => 'https://github.com/rainlab/blog-plugin'
'name' => "Blog",
'description' => "A robust blogging platform.",
'author' => 'Alexey Bobkov, Samuel Georges',
'icon' => 'icon-pencil',
'homepage' => 'https://github.com/rainlab/blog-plugin'
];
}

/**
* boot the module events.
*/
public function boot()
{
$this->bootPageManagerLookups();
}

/**
* registerComponents
*/
public function registerComponents()
{
return [
'RainLab\Blog\Components\Post' => 'blogPost',
'RainLab\Blog\Components\Posts' => 'blogPosts',
'RainLab\Blog\Components\Categories' => 'blogCategories',
'RainLab\Blog\Components\RssFeed' => 'blogRssFeed'
\RainLab\Blog\Components\Post::class => 'blogPost',
\RainLab\Blog\Components\Posts::class => 'blogPosts',
\RainLab\Blog\Components\Categories::class => 'blogCategories',
\RainLab\Blog\Components\RssFeed::class => 'blogRssFeed',
];
}

/**
* registerPermissions
*/
public function registerPermissions()
{
return [
'rainlab.blog.manage_settings' => [
'tab' => 'rainlab.blog::lang.blog.tab',
'label' => 'rainlab.blog::lang.blog.manage_settings'
'tab' => "Blog",
'label' => "Manage blog settings",
],
'rainlab.blog.access_posts' => [
'tab' => 'rainlab.blog::lang.blog.tab',
'label' => 'rainlab.blog::lang.blog.access_posts'
'tab' => "Blog",
'label' => "Manage the blog posts",
],
'rainlab.blog.access_categories' => [
'tab' => 'rainlab.blog::lang.blog.tab',
'label' => 'rainlab.blog::lang.blog.access_categories'
'tab' => "Blog",
'label' => "Manage the blog categories",
],
'rainlab.blog.access_other_posts' => [
'tab' => 'rainlab.blog::lang.blog.tab',
'label' => 'rainlab.blog::lang.blog.access_other_posts'
'tab' => "Blog",
'label' => "Manage other users blog posts",
],
'rainlab.blog.access_import_export' => [
'tab' => 'rainlab.blog::lang.blog.tab',
'label' => 'rainlab.blog::lang.blog.access_import_export'
'tab' => "Blog",
'label' => "Allowed to import and export posts",
],
'rainlab.blog.access_publish' => [
'tab' => 'rainlab.blog::lang.blog.tab',
'label' => 'rainlab.blog::lang.blog.access_publish'
]
'tab' => "Blog",
'label' => "Allowed to publish posts",
],
];
}

/**
* registerNavigation
*/
public function registerNavigation()
{
return [
'blog' => [
'label' => 'rainlab.blog::lang.blog.menu_label',
'url' => Backend::url('rainlab/blog/posts'),
'icon' => 'icon-pencil',
'iconSvg' => 'plugins/rainlab/blog/assets/images/blog-icon.svg',
'label' => "Blog",
'url' => Backend::url('rainlab/blog/posts'),
'icon' => 'icon-pencil',
'iconSvg' => 'plugins/rainlab/blog/assets/images/blog-icon.svg',
'permissions' => ['rainlab.blog.*'],
'order' => 300,

'order' => 300,
'sideMenu' => [
'new_post' => [
'label' => 'rainlab.blog::lang.posts.new_post',
'icon' => 'icon-plus',
'url' => Backend::url('rainlab/blog/posts/create'),
'permissions' => ['rainlab.blog.access_posts']
'label' => "New Post",
'icon' => 'icon-plus',
'url' => Backend::url('rainlab/blog/posts/create'),
'permissions' => ['rainlab.blog.access_posts'],
],
'posts' => [
'label' => 'rainlab.blog::lang.blog.posts',
'icon' => 'icon-copy',
'url' => Backend::url('rainlab/blog/posts'),
'permissions' => ['rainlab.blog.access_posts']
'label' => "Posts",
'icon' => 'icon-copy',
'url' => Backend::url('rainlab/blog/posts'),
'permissions' => ['rainlab.blog.access_posts'],
],
'categories' => [
'label' => 'rainlab.blog::lang.blog.categories',
'icon' => 'icon-list-ul',
'url' => Backend::url('rainlab/blog/categories'),
'permissions' => ['rainlab.blog.access_categories']
]
]
]
'label' => "Categories",
'icon' => 'icon-list-ul',
'url' => Backend::url('rainlab/blog/categories'),
'permissions' => ['rainlab.blog.access_categories'],
],
],
],
];
}

/**
* registerSettings
*/
public function registerSettings()
{
return [
'blog' => [
'label' => 'rainlab.blog::lang.blog.menu_label',
'description' => 'rainlab.blog::lang.blog.settings_description',
'category' => 'rainlab.blog::lang.blog.menu_label',
'label' => "Blog Settings",
'description' => "Manage blog settings",
'category' => "Blog",
'icon' => 'icon-pencil',
'class' => 'RainLab\Blog\Models\Settings',
'class' => \RainLab\Blog\Models\Setting::class,
'order' => 500,
'keywords' => 'blog post category',
'permissions' => ['rainlab.blog.manage_settings']
]
'permissions' => ['rainlab.blog.manage_settings'],
],
];
}

/**
* Register method, called when the plugin is first registered.
* bootPageManagerLookups registers menu items for the RainLab.Pages plugin
*/
public function register()
{
/*
* Register the image tag processing callback
*/
TagProcessor::instance()->registerCallback(function($input, $preview) {
if (!$preview) {
return $input;
}

return preg_replace('|\<img src="image" alt="([0-9]+)"([^>]*)\/>|m',
'<span class="image-placeholder" data-index="$1">
<span class="upload-dropzone">
<span class="label">'. trans('rainlab.blog::lang.post.dropzone') .'</span>
<span class="indicator"></span>
</span>
</span>',
$input);
});
}

public function boot()
protected function bootPageManagerLookups()
{
/*
* Register menu items for the RainLab.Pages plugin
*/
Event::listen('cms.pageLookup.listTypes', function() {
return [
'blog-category' => 'rainlab.blog::lang.menuitem.blog_category',
'all-blog-categories' => ['rainlab.blog::lang.menuitem.all_blog_categories', true],
'blog-post' => 'rainlab.blog::lang.menuitem.blog_post',
'all-blog-posts' => ['rainlab.blog::lang.menuitem.all_blog_posts', true],
'category-blog-posts' => ['rainlab.blog::lang.menuitem.category_blog_posts', true],
'blog-category' => "Blog Category",
'all-blog-categories' => ["All Blog Categories", true],
'blog-post' => "Blog Post",
'all-blog-posts' => ["All Blog Posts", true],
'category-blog-posts' => ["Blog Category Posts", true],
];
});

Event::listen('pages.menuitem.listTypes', function() {
return [
'blog-category' => 'rainlab.blog::lang.menuitem.blog_category',
'all-blog-categories' => 'rainlab.blog::lang.menuitem.all_blog_categories',
'blog-post' => 'rainlab.blog::lang.menuitem.blog_post',
'all-blog-posts' => 'rainlab.blog::lang.menuitem.all_blog_posts',
'category-blog-posts' => 'rainlab.blog::lang.menuitem.category_blog_posts',
'blog-category' => "Blog Category",
'all-blog-categories' => "All Blog Categories",
'blog-post' => "Blog Post",
'all-blog-posts' => "All Blog Posts",
'category-blog-posts' => "Blog Category Posts",
];
});

Event::listen(['cms.pageLookup.getTypeInfo', 'pages.menuitem.getTypeInfo'], function($type) {
if ($type == 'blog-category' || $type == 'all-blog-categories') {
if ($type === 'blog-category' || $type === 'all-blog-categories') {
return Category::getMenuTypeInfo($type);
}
elseif ($type == 'blog-post' || $type == 'all-blog-posts' || $type == 'category-blog-posts') {
elseif ($type === 'blog-post' || $type === 'all-blog-posts' || $type === 'category-blog-posts') {
return Post::getMenuTypeInfo($type);
}
});

Event::listen(['cms.pageLookup.resolveItem', 'pages.menuitem.resolveItem'], function($type, $item, $url, $theme) {
if ($type == 'blog-category' || $type == 'all-blog-categories') {
if ($type === 'blog-category' || $type === 'all-blog-categories') {
return Category::resolveMenuItem($item, $url, $theme);
}
elseif ($type == 'blog-post' || $type == 'all-blog-posts' || $type == 'category-blog-posts') {
elseif ($type === 'blog-post' || $type === 'all-blog-posts' || $type === 'category-blog-posts') {
return Post::resolveMenuItem($item, $url, $theme);
}
});
Expand Down
Loading
Loading