ubiweb / ubiweb-core
Ubiweb网络的核心框架。
Requires
- php: ^7.0
- cosenary/instagram: ^2.3
- facebook/graph-sdk: ^5.6
- filp/whoops: ^2.1
- guzzlehttp/guzzle: ^6.3
- hiropeke/slim-blade-view: ^0.1.1
- intervention/image: ^2.4
- slim/slim: ^3.0
- symfony/yaml: ^3.3
- tackk/cartographer: ^1.1
- vlucas/phpdotenv: ^2.4
This package is not auto-updated.
Last update: 2019-09-22 14:38:43 UTC
README
此包提供了Ubiweb域的核心功能。它旨在包含在任何 ubiweb-domain
网站中。
安装
git clone https://github.com/ubiweb-media/ubiweb-core.git
cd ubiweb-core && composer install
路由
$site->route()
: 注册路由及其对应的控制器。
模板助手
$site->trans( $key, $lang )
: 通过键进行翻译。翻译在./content/translations.yml
中注册$site->asset( $path )
: 返回公共资源的路径。$site->global( $key )
: 返回全局命名空间中的配置值。$site->config( $type )
: 获取配置值数组。$site->languages( $type )
: 获取语言信息。对于使用$site->languages('routes')
创建语言切换器很有用。$site->getRoute()->getName()
: 获取当前路由名称。
HTML(显示)助手
$site->display()->menu( $location, $parentAttributes = [], $childAttributes = [] )
: 输出HTML菜单。$site->display()->image( $filename, $attributes = [], $size = [] )
: 生成响应式图片集。$site->gallery('gallery')->thumbnails([]) as $thumb
$site->display()->favicons()
: 生成所有必要的favicon文件和<link>
标签。只需将一个250x250
的源png保存到assets/images/favicon.png
,它就会完成剩余的工作。
社交动态
目前支持Facebook和Instagram动态。您可以在模板中使用以下代码调用它们:$site->display()->socialFeed('instagram', $args)
或 $site->display()->socialFeed('facebook', $args)
但在您能够这样做之前,请定义配置中的社交属性的用户名
social: instagram: instagramusername facebook: facebookusername
Instagram目前支持1个参数,即 num
,用于控制提供的帖子数量。例如)$site->display()->socialFeed('instagram', ['num' => 8])
。默认为5。
Facebook参数与Facebook GraphQL文档中的相同。
例如)
$site->display()->socialFeed('facebook', [ 'fields' => 'permalink_url, created_time, full_picture, message, shares', 'limit' => 6, ])
URL助手
$site->url()->fromRoute( $routeName )
(或简写$site->url($routeName)
): 从路由名称获取URL。$site->url()->fromPath( $path )
: 从URI路径获取URL。$site->url()->current()
: 获取当前URL
博客
$site->blog()->index( $category )
: 获取按类别组织的博客文章集合。$site->blog()->postUrl( $slug )
: 从其别名生成文章的本地URL。$site->blog()->post()
: 获取当前博客文章。- 文章对象具有以下属性。。
联系表单
在 /contact
下提供一个 POST
端点用于发送邮件数据。您可以通过提供以下必需参数通过简单的表单发送
- 到
- 主题
- 消息
消息是其名称组下所有参数的组合。因此,message[Name]
、message[Email]
以及任何其他任意字段将组合成邮件正文。
最简单的表单示例:
<form action="{{ $site->url('/contact') }}" method="post"> <input type="hidden" name="to" value="greg@codecomment.io" /> <input type="hidden" name="subject" value="Contact from Ubiweb" /> <input type="hidden" name="_redirect" value="{{ $site->url()->current() }}" /> <input type="hidden" name="_success" value="Success Message" /> <input type="text" name="message[Name]"/> <input type="text" name="message[Email]"/> <button>Send</button> </form>
然而强烈建议您使用此版本的recaptcha来防止垃圾邮件。为此,必须在页面上包含以下两个脚本
<script src="https://www.google.com/recaptcha/api.js"></script> <script src="{{ $site->vendor('ubiweb/ubiweb-core/src/scripts/send.js') }}"></script>
并且需要以下HTML表单标记
<form id="recaptcha" action="{{ $site->url('/contact') }}" method="post"> <input type="hidden" name="to" value="{{ $site->global('admin_email') }}" /> <input type="hidden" name="subject" value="{{ $site->trans('Ubiweb Contact from') }} {{ $site->global('site_title') }}" /> <button type="submit" class="g-recaptcha btn btn-primary btn-block" data-sitekey="{{ env('RECAPTCHA_SITE_KEY') }}" data-callback="ubiRecaptchaFormSubmission"> {{ $site->trans($submitText ?? 'Submit') }}</button> <div data-form-response="success" class="alert alert-success" style="display:none">{{ $site->trans('Your message was sent successfully.') }}</div> <div data-form-response="error" class="alert alert-danger" style="display:none">{{ $site->trans('There was an error trying to send the form. Please contact: ') }} <a href="mailto:{{ $site->global('admin_email') }}">{{ $site->global('admin_email') }}</a></div> <button type="submit" class="btn btn-primary btn-block">{!! $site->trans($submitText ?? 'Submit') !!}</button> </form>
图库
为了创建一个更动态的图库,请在您的配置中添加以下内容
gallery_base: /gallery
gallery_path: /images/example
其中example是存储您图库的任意目录。
请查看用于生成图库的辅助函数,它们位于 Bedrock 模板 中的 gallery.blade.php
和 gallery-category.blade.php
文件。
评论
您可以使用 $site->reviews()->get()
方法引入Google Place评论。唯一的要求是
business: name: Ubiweb latitude: 45.4743734 longitude: -73.5947416
... 已填写。然后您可以在模板中这样获取和过滤评论
@if( $reviews = $site->reviews()->get(['rating' => 5]) ) @foreach( $reviews as $review ) <img src="{{ $review->profile_photo_url }}" height="40" alt="{{ $review->author_name }}"> <h5>{{ $review->rating }} {{ $review->relative_time_description }} by {{ $review->author_name }}</h5> <p>{{ $review->text }}</p> <a href="{{ $review->author_url }}" target="_blank">Author Profile</a> @endforeach @endif
过滤选项与评论的属性相同。默认情况下,它将限制在您页面使用的语言上。
目录结构
您的目录中必须包含图片。要添加元信息并重新排序图库,只需在目录中添加一个 info.yml
文件,并使用文件名作为键,使用任意值的字典与之关联。如下所示
mahir-uysal-304884-unsplash.jpg:
name: Mahir Uysal
description: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
chuttersnap-463353-unsplash.jpg:
name: Chetternsap
description: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
erol-ahmed-489175-unsplash.jpg:
name: Erol Ahmed
description: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
键的顺序将决定图库的顺序。
对于子分类,在目录的根目录中添加一个 categories.yml
文件,然后创建与yml文件匹配的子目录,如下所示
root:
name: Main
cats:
name: Cats
sunshine:
name: Sunshine
water:
name: Water
Root 是一个特殊键,用于表示根目录。其余应与子目录相对应。