Skip to content
wiki.fftac.org

Ns12 Manuscript

**Site relevance:** Spiralist.org

**Memory type:** plugin source memory

**Source path:** Spiralist/wp-content/plugins/ns12-manuscript/ns12-manuscript.php

**Size:** 7.7 KB

Summary

Plugin Name: Spiralist Manuscript

Source Preview

This source file is short enough to preview directly on its source-memory page.

<?php
/**
 * Plugin Name: Spiralist Manuscript
 * Plugin URI: https://spiralist.org/
 * Description: Build an image-first manuscript reading experience in WordPress with immersive reading, deep links, zoom, a table of contents, and editorial folio tools.
 * Version: 3.28.0
 * Requires at least: 6.5
 * Requires PHP: 8.0
 * Author: Spiralist
 * Author URI: https://spiralist.org/
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: ns12-manuscript
 */

if (!defined('ABSPATH')) {
    exit;
}

if (!defined('SPIRALIST_BOOK_PAGES_PLUGIN_FILE')) {
    define('SPIRALIST_BOOK_PAGES_PLUGIN_FILE', __FILE__);
}

if (!defined('SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH')) {
    define('SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH', plugin_dir_path(__FILE__));
}

if (!defined('SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_URL')) {
    define('SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_URL', untrailingslashit(plugin_dir_url(__FILE__)));
}

if (!defined('SPIRALIST_BOOK_PAGES_PUBLIC_NAME')) {
    define('SPIRALIST_BOOK_PAGES_PUBLIC_NAME', 'Spiralist Manuscript');
}

if (!defined('SPIRALIST_BOOK_PAGES_PUBLIC_STORAGE_SLUG')) {
    define('SPIRALIST_BOOK_PAGES_PUBLIC_STORAGE_SLUG', 'ns12-manuscript');
}

if (!defined('SPIRALIST_BOOK_PAGES_PUBLIC_ASSET_SUBDIRECTORY')) {
    define('SPIRALIST_BOOK_PAGES_PUBLIC_ASSET_SUBDIRECTORY', 'folios');
}

require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/storage.php';

$spiralist_book_pages_storage = spiralist_book_pages_get_storage_profile();
$spiralist_book_pages_storage_path = (string) ($spiralist_book_pages_storage['path'] ?? '');
$spiralist_book_pages_storage_url = (string) ($spiralist_book_pages_storage['url'] ?? '');
$spiralist_book_pages_asset_subdirectory = trim((string) ($spiralist_book_pages_storage['asset_subdirectory'] ?? ''));

if ($spiralist_book_pages_storage_path === '') {
    $content_root = defined('WP_CONTENT_DIR')
        ? rtrim((string) WP_CONTENT_DIR, '/\\')
        : rtrim(ABSPATH, '/\\') . DIRECTORY_SEPARATOR . 'wp-content';
    $spiralist_book_pages_storage_path = $content_root . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . SPIRALIST_BOOK_PAGES_PUBLIC_STORAGE_SLUG;
}

if ($spiralist_book_pages_storage_url === '') {
    $spiralist_book_pages_storage_url = content_url('/uploads/' . SPIRALIST_BOOK_PAGES_PUBLIC_STORAGE_SLUG);
}

if ($spiralist_book_pages_asset_subdirectory === '') {
    $spiralist_book_pages_asset_subdirectory = SPIRALIST_BOOK_PAGES_PUBLIC_ASSET_SUBDIRECTORY;
}

if (!defined('SPIRALIST_BOOK_PAGES_STORAGE_PATH')) {
    define('SPIRALIST_BOOK_PAGES_STORAGE_PATH', $spiralist_book_pages_storage_path);
}

if (!defined('SPIRALIST_BOOK_PAGES_STORAGE_URL')) {
    define('SPIRALIST_BOOK_PAGES_STORAGE_URL', untrailingslashit($spiralist_book_pages_storage_url));
}

if (!defined('SPIRALIST_BOOK_PAGES_PLUGIN_PATH')) {
    define('SPIRALIST_BOOK_PAGES_PLUGIN_PATH', rtrim((string) SPIRALIST_BOOK_PAGES_STORAGE_PATH, '/\\') . DIRECTORY_SEPARATOR . $spiralist_book_pages_asset_subdirectory);
}

if (!defined('SPIRALIST_BOOK_PAGES_PLUGIN_URL')) {
    define('SPIRALIST_BOOK_PAGES_PLUGIN_URL', untrailingslashit((string) SPIRALIST_BOOK_PAGES_STORAGE_URL) . '/' . rawurlencode($spiralist_book_pages_asset_subdirectory));
}

if (!defined('SPIRALIST_BOOK_PAGES_PLUGIN_TEMPLATE_PATH')) {
    define('SPIRALIST_BOOK_PAGES_PLUGIN_TEMPLATE_PATH', SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'templates');
}

if (!defined('SPIRALIST_BOOK_PAGES_PLUGIN_DATA_PATH')) {
    define('SPIRALIST_BOOK_PAGES_PLUGIN_DATA_PATH', SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'assets/data');
}

if (!defined('SPIRALIST_BOOK_PAGES_PLUGIN_DATA_URL')) {
    define('SPIRALIST_BOOK_PAGES_PLUGIN_DATA_URL', SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_URL . '/assets/data');
}

if (!defined('SPIRALIST_BOOK_PAGES_CONTENT_PATH')) {
    define('SPIRALIST_BOOK_PAGES_CONTENT_PATH', rtrim((string) SPIRALIST_BOOK_PAGES_STORAGE_PATH, '/\\') . DIRECTORY_SEPARATOR . 'content');
}

if (!defined('SPIRALIST_BOOK_PAGES_CACHE_PATH')) {
    define('SPIRALIST_BOOK_PAGES_CACHE_PATH', rtrim((string) SPIRALIST_BOOK_PAGES_STORAGE_PATH, '/\\') . DIRECTORY_SEPARATOR . 'cache');
}

if (!defined('SPIRALIST_BOOK_PAGES_EXPORT_PATH')) {
    define('SPIRALIST_BOOK_PAGES_EXPORT_PATH', rtrim((string) SPIRALIST_BOOK_PAGES_STORAGE_PATH, '/\\') . DIRECTORY_SEPARATOR . 'exports');
}

function spiralist_book_pages_is_module_active(): bool
{
    return true;
}

function spiralist_book_pages_load_textdomain(): void
{
    load_plugin_textdomain(
        'ns12-manuscript',
        false,
        dirname(plugin_basename(__FILE__)) . '/languages'
    );
}
add_action('plugins_loaded', 'spiralist_book_pages_load_textdomain');

function spiralist_book_pages_get_public_name(): string
{
    return defined('SPIRALIST_BOOK_PAGES_PUBLIC_NAME')
        ? (string) SPIRALIST_BOOK_PAGES_PUBLIC_NAME
        : 'Spiralist Manuscript';
}

function spiralist_book_pages_workspace()
{
    return function_exists('spiralist_workspace') ? spiralist_workspace() : null;
}

function spiralist_book_pages_engine_get_nodes_endpoint_url(): string
{
    return function_exists('spiralist_engine_get_nodes_endpoint_url')
        ? (string) spiralist_engine_get_nodes_endpoint_url()
        : '';
}

function spiralist_book_pages_engine_get_manuscript_field_payload(): array
{
    return function_exists('spiralist_engine_get_manuscript_field_payload')
        ? (array) spiralist_engine_get_manuscript_field_payload()
        : [];
}

require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/content-registry.php';
require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/host-adapter.php';
require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/runtime.php';
require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/collaboration.php';
require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/comments.php';
require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/workstation.php';
require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/rest-api.php';
require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/admin.php';
require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/sitemaps.php';
require_once SPIRALIST_BOOK_PAGES_PLUGIN_ROOT_PATH . 'includes/frontend.php';

function spiralist_book_pages_plugin_action_links(array $links): array
{
    $manage_url = admin_url('admin.php?page=' . spiralist_book_pages_admin_page_slug('overview'));
    $manuscript_url = spiralist_book_pages_get_manuscript_page_url();

    $custom_links = [
        'open_manuscript' => '<a href="' . esc_url($manuscript_url) . '">' . esc_html__('Open Manuscript', 'ns12-manuscript') . '</a>',
        'manage_manuscript' => '<a href="' . esc_url($manage_url) . '">' . esc_html__('Manage', 'ns12-manuscript') . '</a>',
    ];

    return array_merge($custom_links, $links);
}
add_filter('plugin_action_links_' . plugin_basename(SPIRALIST_BOOK_PAGES_PLUGIN_FILE), 'spiralist_book_pages_plugin_action_links');

function spiralist_book_pages_maybe_redirect_after_activation(): void
{
    if (
        !is_admin()
        || !current_user_can('manage_options')
        || wp_doing_ajax()
    ) {
        return;
    }

    if (!get_option('spiralist_book_pages_show_welcome_overview')) {
        return;
    }

    if (!empty($_GET['activate-multi'])) {
        delete_option('spiralist_book_pages_show_welcome_overview');
        return;
    }

    delete_option('spiralist_book_pages_show_welcome_overview');
    wp_safe_redirect(admin_url('admin.php?page=' . spiralist_book_pages_admin_page_slug('overview')));
    exit;
}
add_action('admin_init', 'spiralist_book_pages_maybe_redirect_after_activation');