dukt/craft-follow

此包已废弃,不再维护。作者建议使用dukt/follow包。
此包的最新版本(1.0.1)没有可用的许可证信息。

Craft CMS 的关注插件

维护者

详细信息

github.com/dukt/follow

源代码

问题

安装: 15

依赖项: 0

建议者: 0

安全: 0

星星: 13

关注者: 6

分支: 1

开放问题: 2

类型:craft-plugin

1.0.1 2017-09-29 00:02 UTC

This package is auto-updated.

Last update: 2022-02-01 12:58:51 UTC


README

一个简单的插件,用于连接到 Follow 的 API。

安装

  1. 下载插件的最新版本
  2. follow 插件文件夹放入 craft/plugins
  3. 设置 > 插件 控制面板中安装 Follow

模板

关注

您关注的用户。

{% if not currentUser %}
    <p>You need to <a href="{{url('follow/login')}}">login</a> in order to see the users you follow.</p>
{% else %}
    {% set users = craft.follow.getFollowing() %}

    {% if users|length > 0 %}

        <p>You are following {{users|length}} users.</p>

        <div class="row">
            {% for user in users %}
                <div class="col-md-4">
                    {% include 'follow/_user' with { user: user } %}
                </div>
            {% endfor %}
        </div>

    {% else %}
        <p>{{ "You are not following anyone."|t }}</p>
    {% endif %}

{% endif %}

粉丝

关注您的用户。

{% if not currentUser %}
    <p>{{ 'You need to <a href="{url}">login</a> in order to see you followers.'|t({ url: url('follow/login') })|raw }}</p>
{% else %}
    {% set users = craft.follow.getFollowers(currentUser.id) %}

    {% if users %}

        <p>{{ "You have {count} followers."|t({ count: users|length }) }}</p>

        <div class="row">
            {% for user in users %}
                <div class="col-md-4">
                    {% include 'follow/_user' with { user: user } %}
                </div>
            {% endfor %}
        </div>

    {% else %}
        <p>{{ "No one is following you." }}</p>
    {% endif %}
{% endif %}

活动

您关注的用户最近的条目。

{% if not currentUser %}
    <p>{{ 'You need to <a href="{url}">login</a> in order to see the activity of users you follow.'|t({ url: url('follow/login') })|raw }}</p>
{% else %}
    {% set followingUsers = craft.follow.getFollowing( user.id ) %}

    {% set followingUserIds = [] %}
    {% for followingUser in followingUsers %}
        {% set followingUserIds = followingUserIds|merge([ followingUser.id ]) %}
    {% endfor %}

    {% if followingUserIds|length > 0 %}

        {% set entries = craft.entries.authorId(followingUserIds).find() %}

        {% if entries|length %}
            {% for entry in entries %}
                <div class="media">
                    <div class="media-left text-center">

                        {% if entry.author.photoUrl %}
                            {% set photoUrl = entry.author.photoUrl(80) %}
                        {% else %}
                            {% set photoUrl = resourceUrl('images/user.gif') %}
                        {% endif %}

                        <img src="{{ photoUrl }}" width="80" class="img-circle" />

                        <p>{{ entry.author.fullName }}</p>

                    </div>

                    <div class="media-body">

                        <h4 class="media-heading">{{ entry.title }}</h4>

                        <p>
                            <small>{{ entry.postDate.nice }}</small>
                        </p>

                        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia, unde molestias odit mollitia sint. Similique, nesciunt, sunt, magnam enim asperiores totam consequuntur ratione nemo quam ut vitae accusantium blanditiis esse.</p>

                        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Officia, unde molestias odit mollitia sint. Similique, nesciunt, sunt, magnam enim asperiores totam consequuntur ratione nemo quam ut vitae accusantium blanditiis esse.</p>

                    </div>
                </div>

                <hr>
            {% endfor %}
        {% else %}
            <p>{{ "Start following some users to see their recent entries."|t }}</p>
        {% endif %}
    {% else %}
        <p>{{ "Start following some users to see their recent entries."|t }}</p>
    {% endif %}

{% endif %}

user.html

{% set followers = craft.follow.getFollowers(user.id) %}

<div class="row">
    <div class="col-md-12">

        <div class="panel panel-default">
            <div class="panel-body">

                <div class="row">
                    <div class="col-sm-4">
                        {% if user.photoUrl %}
                            {% set photoUrl = user.photoUrl %}
                        {% else %}
                            {% set photoUrl = resourceUrl('images/user.gif') %}
                        {% endif %}

                        <img src="{{ photoUrl }}" width="90" class="img-circle" />
                    </div>
                    <div class="col-sm-8">

                        <h5>{{ user.fullName }}</h5>

                        {% set followersCount = followers|length %}

                        {% if followersCount > 1 %}
                            <p>{{ "{count} followers"|t({ count: followersCount }) }}</p>
                        {% else %}
                            <p>{{ "{count} follower"|t({ count: followersCount }) }}</p>
                        {% endif %}

                        {% if currentUser and currentUser.id != user.id %}
                            {% if craft.follow.isFollow(user.id) %}
                                <a class="btn btn-default btn-sm" href="{{actionUrl('follow/stopFollowing', {id:user.id})}}">{{ "Unfollow"|t }}</a>
                            {% else %}
                                <a class="btn btn-default btn-sm btn-primary" href="{{actionUrl('follow/startFollowing', {id:user.id})}}">{{ "Follow"|t }}</a>
                            {% endif %}
                        {% else %}
                            <div class="btn btn-default btn-sm btn-primary disabled">{{ "Follow"|t }}</div>
                        {% endif %}

                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

API

FollowVariable

  • isFollow($elementId)
  • getFollowers($userId = null)
  • getFollowing($userId = null)