定制 strangefate/blogger 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

strangefate/blogger

Composer 安装命令:

composer require strangefate/blogger

包简介

A handler for easy adding a blog or news articles to a laravel project

关键字:

README 文档

README

Package Installation

This module has some quick templates for adding a blog to your Laravel site. It includes support for CKEditor, a WYSIWYG editor with the ability to directly attach images to your post. The CKEditor requires Vue.js, but you are free to customize your project to exclude this. There is also a watered down editor with a basic text editor if you do not wish to use CKEditor.

Require package

composer require strangefate/blogger

Run migration to add the required table for comments, likes and reports to the database

php artisan migrate

You can public the config file to overwrite some of the basic configuration, including the slug for post model.

php artisan vendor:publish --provider=StrangeFate\Blogger\BloggerServiceProvider --tag=config

CKEditor (WYSIWYG)

To make use of CKEditor, run this artisan command which will automate most of the installation for you.

php artisan blogeditor:install

This will install the Vue CKEditor module through npm and add most of the modules required. You will still need to add a javascript processor to upload images attached or dragged to the editor. To do this, add a method to the default Vue instance with the path for the image upload form.

import CustomUploadAdapter from './classes/ckeditor-upload-adapter-class'; //added by blogeditor:install

const app = new Vue({
    el: '#app',
    mounted() {},

    // This code will be inserted into your app.js file. Customize this code for your project. You can make as many of these modules as needed for your project.
    methods: {
    	CustomUploadAdapterPlugin( editor ) {
		    editor.plugins.get( 'FileRepository' ).createUploadAdapter = ( loader ) => {
	    	    loader.uploadUrl = '/api/posts/editorimages';
	        	return new CustomUploadAdapter( loader );
		    }
		}
    },
    //end required code.
});

Because CKEditor uses HTML tags, you may not want to use blades {{}} sanitizer. Blogger has it's own sanatizer method for stripping down code. You can specify what tags are safe to keep in your project by editing the safe_tags array in the config\blogger.php after publishing it.

'sanitizer' => [
    'safe_tags' => [
        'pre','b','em','u','ul','li','ol','p','br','tt','hr','i','table','tr','th','td',
    ]
],

The blogger will also resize images that are uploaded to save file space. You can customize the maximum dimensions of images in the blogger config file.

'social' => [ 
    'height' => 601,
    'width' => 1147,
],

Routes and Controllers

Now you will need to setup the routes and controllers for your project. Because of the multiple support cases that surround a blog (mostly from authorization), these are not done by default. Blogger does have some quick and easy Controller classes you can use to expedite this process. It is recommended that you create a new controller and inherit these classes and overwrite the methods as needed.

web.php

Route::resource('/posts', 'PostController');
Route::post('/posts/{post}/comment', 'PostController@comment');
Route::post('/posts/{post}/like', 'PostController@like');
Route::get('/posts/{post}/image', 'PostController@image');
php artisan make:controller PostController
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use StrangeFate\Blogger\Controllers\BloggerPostWithEditorController;  //BloggerPostController without CKEdit

class PostController extends BloggerPostWithEditorController  //BloggerPostController without CKEdit
{
	public function __construct() {
        $this->middleware('auth')->except(['index','show', 'image']);
    }
}

For CKEditor module, there is also an API based controller to handle image uploads. Like the previous example, you should create a new controller and inherit the CKEditorImageUploadController. api.php

Route::post('/posts/images', 'api\PostImageController@image_upload'); //single image upload (ImageSelector.vue)
Route::post('/posts/editorimages', 'api\PostImageController@editor_image_upload');  //CKeditor Image. This URL should match what you put in for the loader.uploadUrl in the app.js module.
php artisan make:controller api\PostImageController
<?php

namespace App\Http\Controllers\api;

use Illuminate\Http\Request;
use StrangeFate\Blogger\Controllers\CKEditorImageUploadController;

class PostImageController extends CKEditorImageUploadController {
   
   public function __construct() {
       $this->middleware(['auth:api']);
   }  
}

Views

This project has ready to use views for rapidly customizing you're solution. It's pretty likely that you will want to over write them. To do this, publish the views to your project and format to your desire.

php artisan vendor:publish --provider=StrangeFate\Blogger\BloggerServiceProvider --tag=views

Views

@include('blogger::index') {{-- Index layout for base overview --}}
@include('blogger::card') {{-- Basic card layout for index view --}}
@include('blogger::create') {{-- Create form with image upload --}}
@include('blogger::ck_create') {{-- Create form with text editor and image picker --}}
@include('blogger::edit') {{-- Create form with image upload --}}
@include('blogger::ck_edit') {{-- Edit form with text editor and image picker --}}
@include('blogger::show') {{-- Article view --}}
@include('blogger::templates.text-editors') {{-- Note to be used. Example text editors. --}}

Comments

The Blogger uses strangefate\commenthandler for post comments and likes and will automatically be pulled in with this project. Review the comment handler documenation for further configuration details.

strangefate/blogger 适用场景与选型建议

strangefate/blogger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 12 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「blog」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 strangefate/blogger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 strangefate/blogger 我们能提供哪些服务?
定制开发 / 二次开发

基于 strangefate/blogger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 42
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-16