Добавление простого блока в 66biolinks

Для добавления простого блока Biolink (например вывод почты, номера телефона и т.д.) необходимо:

  1. Название будущего блока ( пример Example block )
  2. Ключ для будущего блока ( символы a-z, 0-9 и _, пример example_block )
  3. Ключ для данных будущего блока ( символы a-z, 0-9 и _, пример example_field )
  4. Название поля данных будущего блока ( пример Мой сайт )

В инструкции ниже название блока будет в виде конструкции {{block_name}}, ключ блока в виде конструкции {{block_key}}, ключ данных в виде конструкции {{block_field}}, поле данных {{block_field_name}}


Папка для добавления: ./themes/ваша_тема/views/link/settings/biolink_blocks/{{block_key}}

Пример: ./themes/ваша_тема/views/link/settings/biolink_blocks/example_block


Файл для добавления: ./themes/ваша_тема/views/link/settings/biolink_blocks/{{block_key}}/{{block_key}}_create_modal.php

Пример: ./themes/ваша_тема/views/link/settings/biolink_blocks/example_block/example_block_create_modal.php

Содержимое файла:

<?php defined('ALTUMCODE') || die() ?>

<div class="modal fade" id="create_biolink_{{block_key}}" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" role="document">
        <div class="modal-content">

            <div class="modal-header">
                <button type="button" data-toggle="modal" data-target="#biolink_link_create_modal" data-dismiss="modal" class="btn btn-sm btn-link"><i class="fa fa-fw fa-chevron-circle-left text-muted"></i></button>
                <h5 class="modal-title"><?= l('create_biolink_{{block_key}}_modal.header') ?></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="<?= l('global.close') ?>">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            
            <div class="modal-body">
                <form name="create_biolink_{{block_key}}" method="post" role="form" enctype="multipart/form-data">
                    <input type="hidden" name="token" value="<?= \Altum\Middlewares\Csrf::get() ?>" required="required" />
                    <input type="hidden" name="request_type" value="create" />
                    <input type="hidden" name="link_id" value="<?= $data->link->link_id ?>" />
                    <input type="hidden" name="block_type" value="{{block_key}}" />

                    <div class="notification-container"></div>

                    <div class="form-group">
                        <label for="{{block_key}}_{{block_field}}"><?= l('create_biolink_{{block_key}}_modal.{{block_field}}.placeholder') ?></label>
                        <input id="{{block_key}}_{{block_field}}" type="text" class="form-control" name="{{block_field}}" value="" maxlength="128" />
                    </div>
                    
                    <div class="text-center mt-4">
                        <button type="submit" name="submit" class="btn btn-block btn-primary" data-is-ajax><?= l('global.submit') ?></button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

Файл для добавления: ./themes/ваша_тема/views/link/settings/biolink_blocks/{{block_key}}/{{block_key}}_update_form.php

Пример: ./themes/ваша_тема/views/link/settings/biolink_blocks/example_block/example_block_update_form.php

Содержимое файла:

<?php defined('ALTUMCODE') || die() ?>

<form name="update_biolink_" method="post" role="form" enctype="multipart/form-data">
    <input type="hidden" name="token" value="<?= \Altum\Middlewares\Csrf::get() ?>" required="required" />
    <input type="hidden" name="request_type" value="update" />
    <input type="hidden" name="block_type" value="{{block_key}}" />
    <input type="hidden" name="biolink_block_id" value="<?= $row->biolink_block_id ?>" />

    <div class="notification-container"></div>

    <div class="form-group">
        <label for="<?= '{{block_key}}_' . $row->biolink_block_id ?>"><?= l('create_biolink_{{block_key}}_modal.{{block_field}}.placeholder') ?></label>
        <input id="<?= '{{block_key}}_' . $row->biolink_block_id ?>" type="text" class="form-control" name="{{block_field}}" value="<?= $row->settings->{{block_field}} ?? '' ?>" maxlength="128" />
    </div>
    
    <button class="btn btn-block btn-gray-300 my-4" type="button" data-toggle="collapse" data-target="#<?= 'display_settings_container_' . $row->biolink_block_id ?>" aria-expanded="false" aria-controls="<?= 'display_settings_container_' . $row->biolink_block_id ?>">
        <?= l('create_biolink_link_modal.display_settings_header') ?>
    </button>

    <div class="collapse" id="<?= 'display_settings_container_' . $row->biolink_block_id ?>">
        <div <?= $this->user->plan_settings->temporary_url_is_enabled ? null : 'data-toggle="tooltip" title="' . l('global.info_message.plan_feature_no_access') . '"' ?>>
            <div class="<?= $this->user->plan_settings->temporary_url_is_enabled ? null : 'container-disabled' ?>">
                <div class="custom-control custom-switch mb-3">
                    <input
                            id="<?= 'link_schedule_' . $row->biolink_block_id ?>"
                            name="schedule" type="checkbox"
                            class="custom-control-input"
                        <?= !empty($row->start_date) && !empty($row->end_date) ? 'checked="checked"' : null ?>
                        <?= $this->user->plan_settings->temporary_url_is_enabled ? null : 'disabled="disabled"' ?>
                    >
                    <label class="custom-control-label" for="<?= 'link_schedule_' . $row->biolink_block_id ?>"><?= l('link.settings.schedule') ?></label>
                    <small class="form-text text-muted"><?= l('link.settings.schedule_help') ?></small>
                </div>
            </div>
        </div>

        <div class="mt-3 schedule_container" style="display: none;">
            <div <?= $this->user->plan_settings->temporary_url_is_enabled ? null : 'data-toggle="tooltip" title="' . l('global.info_message.plan_feature_no_access') . '"' ?>>
                <div class="<?= $this->user->plan_settings->temporary_url_is_enabled ? null : 'container-disabled' ?>">
                    <div class="row">
                        <div class="col">
                            <div class="form-group">
                                <label for="<?= 'link_start_date_' . $row->biolink_block_id ?>"><i class="fa fa-fw fa-clock fa-sm text-muted mr-1"></i> <?= l('link.settings.start_date') ?></label>
                                <input
                                        id="<?= 'link_start_date_' . $row->biolink_block_id ?>"
                                        type="text"
                                        class="form-control"
                                        name="start_date"
                                        value="<?= \Altum\Date::get($row->start_date, 1) ?>"
                                        placeholder="<?= l('link.settings.start_date') ?>"
                                        autocomplete="off"
                                        data-daterangepicker
                                >
                            </div>
                        </div>

                        <div class="col">
                            <div class="form-group">
                                <label for="<?= 'link_end_date_' . $row->biolink_block_id ?>"><i class="fa fa-fw fa-clock fa-sm text-muted mr-1"></i> <?= l('link.settings.end_date') ?></label>
                                <input
                                        id="<?= 'link_end_date_' . $row->biolink_block_id ?>"
                                        type="text"
                                        class="form-control"
                                        name="end_date"
                                        value="<?= \Altum\Date::get($row->end_date, 1) ?>"
                                        placeholder="<?= l('link.settings.end_date') ?>"
                                        autocomplete="off"
                                        data-daterangepicker
                                >
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label for="<?= 'link_display_countries_' . $row->biolink_block_id ?>"><i class="fa fa-fw fa-globe fa-sm text-muted mr-1"></i> <?= l('create_biolink_link_modal.input.display_countries') ?></label>
            <select id="<?= 'link_display_countries_' . $row->biolink_block_id ?>" name="display_countries[]" class="form-control" multiple="multiple">
                <?php foreach(get_countries_array() as $country => $country_name): ?>
                    <option value="<?= $country ?>" <?= in_array($country, $row->settings->display_countries ?? []) ? 'selected="selected"' : null ?>><?= $country_name ?></option>
                <?php endforeach ?>
            </select>
            <small class="form-text text-muted"><?= l('create_biolink_link_modal.input.display_countries_help') ?></small>
        </div>

        <div class="form-group">
            <label for="<?= 'link_display_devices_' . $row->biolink_block_id ?>"><i class="fa fa-fw fa-laptop fa-sm text-muted mr-1"></i> <?= l('create_biolink_link_modal.input.display_devices') ?></label>
            <select id="<?= 'link_display_devices_' . $row->biolink_block_id ?>" name="display_devices[]" class="form-control" multiple="multiple">
                <?php foreach(['desktop', 'tablet', 'mobile'] as $device_type): ?>
                    <option value="<?= $device_type ?>" <?= in_array($device_type, $row->settings->display_devices ?? []) ? 'selected="selected"' : null ?>><?= l('global.device.' . $device_type) ?></option>
                <?php endforeach ?>
            </select>
            <small class="form-text text-muted"><?= l('create_biolink_link_modal.input.display_devices_help') ?></small>
        </div>

        <div class="form-group">
            <label for="<?= 'link_display_languages_' . $row->biolink_block_id ?>"><i class="fa fa-fw fa-language fa-sm text-muted mr-1"></i> <?= l('create_biolink_link_modal.input.display_languages') ?></label>
            <select id="<?= 'link_display_languages_' . $row->biolink_block_id ?>" name="display_languages[]" class="form-control" multiple="multiple">
                <?php foreach(get_locale_languages_array() as $locale => $language): ?>
                    <option value="<?= $locale ?>" <?= in_array($locale, $row->settings->display_languages ?? []) ? 'selected="selected"' : null ?>><?= $language ?></option>
                <?php endforeach ?>
            </select>
            <small class="form-text text-muted"><?= l('create_biolink_link_modal.input.display_languages_help') ?></small>
        </div>

        <div class="form-group">
            <label for="<?= 'link_display_operating_systems_' . $row->biolink_block_id ?>"><i class="fa fa-fw fa-window-restore fa-sm text-muted mr-1"></i> <?= l('create_biolink_link_modal.input.display_operating_systems') ?></label>
            <select id="<?= 'link_display_operating_systems_' . $row->biolink_block_id ?>" name="display_operating_systems[]" class="form-control" multiple="multiple">
                <?php foreach(['iOS', 'Android', 'Windows', 'OS X', 'Linux', 'Ubuntu', 'Chrome OS'] as $os_name): ?>
                    <option value="<?= $os_name ?>" <?= in_array($os_name, $row->settings->display_operating_systems ?? []) ? 'selected="selected"' : null ?>><?= $os_name ?></option>
                <?php endforeach ?>
            </select>
            <small class="form-text text-muted"><?= l('create_biolink_link_modal.input.display_operating_systems_help') ?></small>
        </div>
    </div>


    <div class="mt-4">
        <button type="submit" name="submit" class="btn btn-block btn-primary" data-is-ajax><?= l('global.update') ?></button>
    </div>
</form>

Файл для добавления: ./themes/ваша_тема/views/l/biolink_blocks/{{block_key}}.php

Пример: ./themes/ваша_тема/views/l/biolink_blocks/example_block.php

Содержимое файла:

<?php defined('ALTUMCODE') || die() ?>

<div id="<?= 'biolink_block_id_' . $data->link->biolink_block_id ?>" data-biolink-block-id="<?= $data->link->biolink_block_id ?>" class="col-12 my-2">
    <?= $data->link->settings->{{block_field}} ?>
</div>

Пример:

<?php defined('ALTUMCODE') || die() ?>

<div id="<?= 'biolink_block_id_' . $data->link->biolink_block_id ?>" data-biolink-block-id="<?= $data->link->biolink_block_id ?>" class="col-12 my-2">
    <?= $data->link->settings->example_field ?>
</div>

Файл для изменения: ./app/languages/ваш_язык#active.php

Найти:

return [

Добавить после (в массив):

'link.biolink.blocks.{{block_key}}' => '{{block_name}}',
'create_biolink_{{block_key}}_modal.header' => '{{block_name}}',
'create_biolink_{{block_key}}_modal.{{block_field}}.placeholder' => '{{block_field_name}}',

Пример:

'link.biolink.blocks.example_block' => 'Example block',
'create_biolink_example_block_modal.header' => 'Добавление Example block',
'create_biolink_example_block_modal.example_field.placeholder' => 'Мой сайт',


Файл для изменения: ./app/helpers/Link.php

Найти (функция get_biolink_link):

case 'avatar':

Добавить после:

case '{{block_key}}':

Пример:

case 'example_block':


Файл для изменения: ./app/controllers/BiolinkBlockAjax.php

Найти (Внимание! Код находится в 2 местах, необходимо найти оба):

$individual_blocks = [

Добавить после (Внимание! Код находится в 2 местах, необходимо добавить в оба):

'{{block_key}}',

Пример:

'example_block',

Найти:

private function create_biolink_mail() {

Добавить перед:

private function create_biolink_{{block_key}}() {

        $_POST['link_id'] = (int) $_POST['link_id'];

        $_POST['{{block_field}}'] = mb_substr(Database::clean_string($_POST['{{block_field}}']), 0, 128);

        $type = '{{block_key}}';

        $settings = json_encode([
            '{{block_field}}' => $_POST['{{block_field}}'],

            /* Display settings */
            'display_countries' => [],
            'display_devices' => [],
            'display_languages' => [],
            'display_operating_systems' => [],
        ]);

        /* Database query */
        db()->insert('biolinks_blocks', [
            'user_id' => $this->user->user_id,
            'link_id' => $_POST['link_id'],
            'type' => $type,
            'location_url' => null,
            'settings' => $settings,
            'order' => $this->total_biolink_blocks,
            'datetime' => \Altum\Date::$date,
        ]);

        /* Clear the cache */
        \Altum\Cache::$adapter->deleteItem('link?link_id=' . $_POST['link_id']);

        Response::json('', 'success', ['url' => url('link/' . $_POST['link_id'] . '?tab=links')]);
    }

Найти:

private function update_biolink_mail() {

Добавить перед:

private function update_biolink_{{block_key}}() {

        $_POST['biolink_block_id'] = (int) $_POST['biolink_block_id'];

        /* Display settings */
        $this->process_display_settings();

        if(!$biolink_block = db()->where('biolink_block_id', $_POST['biolink_block_id'])->where('user_id', $this->user->user_id)->getOne('biolinks_blocks')) {
            die();
        }
        $biolink_block->settings = json_decode($biolink_block->settings);

        $_POST['{{block_field}}'] = mb_substr(Database::clean_string($_POST['{{block_field}}']), 0, 128);

        $settings = json_encode([
            'contacts_sms' => $_POST['{{block_field}}'],

            /* Display settings */
            'display_countries' => $_POST['display_countries'],
            'display_devices' => $_POST['display_devices'],
            'display_languages' => $_POST['display_languages'],
            'display_operating_systems' => $_POST['display_operating_systems'],
        ]);

        /* Database query */
        db()->where('biolink_block_id', $_POST['biolink_block_id'])->update('biolinks_blocks', [
            'settings' => $settings,
            'start_date' => $_POST['start_date'],
            'end_date' => $_POST['end_date'],
        ]);

        /* Clear the cache */
        \Altum\Cache::$adapter->deleteItem('link?link_id=' . $biolink_block->link_id);

        Response::json(l('global.success_message.update2'), 'success');
    }


Файл для изменения: ./app/includes/biolink_blocks.php

Найти:

$default_blocks = [

Добавить после (в массив):

'{{block_key}}' => [
        'type' => 'default',
        'icon' => 'fa fa-phone-square-alt',
        'color' => '#63d2ff',
        'has_statistics' => false,
        'display_dynamic_name' => false,
    ],

fa-phone-square-alt можно заменить на любую необходимую иконку из пакета FontAwesome 5.

63d2ff можно заменить на необходимый Вам цвет иконки.

Пример:

'example_block' => [
        'type' => 'default',
        'icon' => 'fa fa-phone-square-alt',
        'color' => '#63d2ff',
        'has_statistics' => false,
        'display_dynamic_name' => false,
    ],

Яндекс.Метрика