定制 venveo/craft-compress 二次开发

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

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

venveo/craft-compress

最新稳定版本:5.0.0

Composer 安装命令:

composer require venveo/craft-compress

包简介

Create smart zip files from Craft assets on the fly

README 文档

README

Compress exposes a variable within Twig to create zip archives from Asset queries as a native Craft asset itself.

Features

  • Compress asset query into a zip file
  • Generate "lazy links": will dispatch a queue job to generate archives, if a user clicks a link before the job is completed or started, the asset will be fetched on-demand and the queue job cancelled.
  • Compressed archives are stored as Assets themselves, so you may query them just like other assets.
  • Retrieve an asset query for the contents of an archive to show what files are contained in it.
  • Automatically forces zip files to be regenerated when a dependent asset is deleted or updated in Craft.

Requirements

  • Craft CMS 3.x-5.x
  • ext-zip PHP extension for creating zip files (also conveniently a Craft requirement)

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require venveo/craft-compress
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Compress.

Configuring Compress

  1. Compress creates its archives as assets in Craft, so you'll need a place to put them. Create a new volume.
  2. Click "Settings" next to the plugin in the plugin list and select a storage volume for archives. It's not recommended to use an existing volume. The volume must have URLs in order for the Twig helper to return download links; however, it will function without it and respect your settings and life choices.

Using Compress

Basic Example

    {# Feel free to provide an array of assets if you prefer! #}
    {% set assets = craft.assets.volume('images') %}
    
    {# 
    Second parameter is whether we want the archive generated on page 
    load or lazily.
    #}
    {% set archive = craft.compress.zip(assets, true, 'My Photos') %}
    
    {# 
    the archive variable is now set to an Archive model, but since 
    we're in lazy mode, the getAsset() response may be null. We can
    either check the .isReady method or we can just get the lazyLink, which will give us an indirect link to the asset.
    #}
    {% if archive.isReady %}
        {% set archiveAsset = archive.getAsset() %}
        <a href="{{ archiveAsset.getUrl() }}">Download All Files</a>
        {% else %}
        <a href="{{ archive.lazyLink}}">Download All Files</a>
    {% endif %}
    
    {# We can get a new AssetQuery with the contents of the archive! #}
    {% set contents = archiveAsset.getContents().all() %}
    <ul>
    {% for file in contents %}
        <li><a href="{{ file.getUrl() }}">{{ file.title }}</a></li>
    {% endfor %}
    </ul>

Advanced Example

This example gets all assets, groups them by the file type, and then generates a lazy link to download all assets of a particular kind.

{% set assets = craft.assets({
    volume: 'local'
}).all() %}

{% for kind, assetGroup in assets|group(a => a.kind) %}
    {% set archive = craft.compress.zip(assetGroup, true) %}
    <strong>{{ kind }} - <a href="{{ archive.lazyLink }}">Download All ({{ archive.isReady ? 'Ready' : 'Not ready' }})</a></strong>
    {% for asset in assetGroup %}
        <li>{{ asset.filename }}</li>
    {% endfor %}
{% endfor %}

Caveats & Limitations

  • Consider the Assets created by Compress to be temporary. Don't try to use them in Asset relation fields. set changes, a new archive asset will be created and the prior will not be automatically deleted.
  • When you provide a name for your archive, it's a good idea to ensure that name is unique to the files you're zipping up. Failure to do so could result in the file not being cached well and being constantly overwritten.

Brought to you by Venveo

统计信息

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

GitHub 信息

  • Stars: 12
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固