pdxlibrary/Alma-Hours-Widget

语言: PHP

git: https://github.com/pdxlibrary/Alma-Hours-Widget

此应用程序使用Ex Libris Alma Hours API创建一个动态HTML小时窗口小部件,用于外部网站...
This application uses the Ex Libris Alma Hours API to create a dynamic HTML hours widget to be used on external websi…
README.md (中文)

Alma Hours Widget

描述

此应用程序使用Ex Libris Alma Hours API创建动态HTML小时窗口小部件,以便在外部网站上显示库的即将到来的小时数。用户只需包含JavaScript和CSS文件,并添加占位符DIV标记,他们希望显示库的小时数,应用程序将处理Alma API的所有通信,结果格式化以及通过动态AJAX生成HTML输出请求。

组态

创建Alma Hours API密钥

您需要转到Alma Developer Network并创建一个应用程序。应用程序名称可以是任何内容(例如:Alma Hours Widget)。 Platfrom应该是“Web应用程序”。在“API管理”选项卡下,添加具有只读访问权限的Configuration API。添加应用程序后,将创建API密钥。在文件顶部的配置部分的alma_hours_widget.php文件中输入此API密钥:

// alma_hours_widget.php
// set your Alma Hours API Key - Replace XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Alma API Key
define("ALMA_HOURS_API_KEY","XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

缓存(推荐)

如果没有缓存,每次显示窗口小部件时都需要查询Alma API。这可能会给API服务器带来沉重且不必要的负载。他的应用程序使用基于磁盘的缓存,默认情况下每天将每个唯一API请求的小时数更新为静态文件一次。 CACHE_FREQUENCY设置可以从“每日”更改为“每小时”或“无”

// alma_hours_widget.php
// set the Caching Frequency - Daily, Hourly or None (default: Daily)
define("CACHE_FREQUENCY","Daily");

要使缓存正常运行,“cache”文件夹必须启用写入访问。

跨站点脚本访问(可选)

如果您要在托管alma_hours_widget.php文件的位置以外的站点上包含您的小时小部件,则需要启用XSS访问。只需在文件顶部配置部分的alma_hours_widget.php中的$ allowed_domains数组中添加您将显示hours小部件的域列表:

// alma_hours_widget.php
// example setting for allowing cross-site scripting (XSS)
$allowed_domains = array("http://www.allowed-website.edu","https://secure.allowed-website.edu");

CSS

CSS可用于完全更改窗口小部件设计的样式。小部件的每个部分都有一个可以用CSS定位的相关类。默认样式表alma_hours_widget.css可用作窗口小部件设计的起点。

<link rel="stylesheet" href="alma_hours_widget.css" />

JS

使用AJAX创建窗口小部件以查询API脚本

<script src="alma_hours_widget.js"></script>

jQuery的

Alma Hours Widget需要在要显示小部件的页面上加载jQuery。

PHP

PHP脚本用于查询REST API接口,清理/格式化输出并将结果反馈为JSON。还可以在此层轻松添加缓存,以加快加载时间并减少对Ex Libris的API请求。

HTML

通过添加类“alma_hours_widget”的DIV标记来添加每个小部件。

基本小部件(显示接下来的7天小时):

<div class="alma_hours_widget" data-library="MILLAR" data-title="Library Hours"></div>
  • 数据库和数据标题属性是必需属性。

数据库

通过导航到Fulfillment Configuration - Configuration Menu,可以在Alma中找到数据库的值。在“您正在配置:”下拉菜单中,选择要为其创建“小时”小组件的库。然后选择Library下的“Opening Hours”。选择“摘要”选项卡以显示库的“代码”。库代码的值应该用于数据库属性,以便为该库创建窗口小部件。

完整用法示例:

<!-- Alma Hours Widget CSS -->
<link rel="stylesheet" href="alma_hours_widget.css" />

<!-- jQuery Library -->
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- Alma Hours Widget JS -->
<script src="alma_hours_widget.js"></script>

<!-- Alma Hours Widget (next 7 days) -->
<div class="alma_hours_widget" data-library="MILLAR" data-title="Basic Hours"></div>

可选的HTML5属性:

  • data-start-date - 用于设置窗口小部件的开始日期
  • data-end-date - 用于设置窗口小部件的结束日期
  • data-date-format - PHP标准日期格式选项(例如“m / d / Y”,“m / d / y”,“m-d-y”等...)
  • data-time-format - PHP标准时间格式选项(例如“g:ia”,“H:i:s”等...)

可以将这些可选的HTML5属性添加到DIV标记占位符,如以下示例所示:

自定义时间/日期格式:

<div class="alma_hours_widget" data-library="MILLAR" data-title="Custom Date/Time Format" data-date-format="m-d-y" data-time-format="H:i:s"></div>

自定义日期范围:

<div class="alma_hours_widget" data-library="MILLAR" data-title="Custom Date Range" data-start-date="2015-11-24" data-end-date="2015-12-05"></div>

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

Alma Hours Widget

Description

This application uses the Ex Libris Alma Hours API to create a dynamic HTML hours widget to be used on external websites to display a library's upcoming hours. Users simply have include the JavaScript and CSS files and add a placeholder DIV tag where they want their library's hours to display and the application will handle all the commuication with the Alma API, formatting of the results and generation of the HTML output via a dynamic AJAX request.

Configuration

Create an Alma Hours API Key

You will need to go to the Alma Developer Network and create an Application. The Application Name can be anything (For example: Alma Hours Widget). The Platfrom should be "Web application". Under the API Management tab, add the Configuration API with read-only access. Once you have added the application, an API Key will be created. Enter this API Key in the alma_hours_widget.php file in the configuration section at the top of the file:

// alma_hours_widget.php
// set your Alma Hours API Key - Replace XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX with your Alma API Key
define("ALMA_HOURS_API_KEY","XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

Caching (recommended)

Without caching, the Alma API would need to be queried every time the widget is displayed. This can put a heavy and unneccessary load on the API server. This his application uses disk based caching to update the hours for each unique API request to a static file once per day by default. The CACHE_FREQUENCY setting can be changed from "Daily" to "Hourly" or "None"

// alma_hours_widget.php
// set the Caching Frequency - Daily, Hourly or None (default: Daily)
define("CACHE_FREQUENCY","Daily");

For caching to function correctly, the "cache" folder must have write-access enabled.

Cross-Site Script Access (optional)

If you will be including your hours widget on a site other than the location where the alma_hours_widget.php file will be hosted, then you will need to enable XSS access. Simply add the list of domains where you will be displaying the hours widget in the $allowed_domains array in the alma_hours_widget.php in the configuration section at the top of the file:

// alma_hours_widget.php
// example setting for allowing cross-site scripting (XSS)
$allowed_domains = array("http://www.allowed-website.edu","https://secure.allowed-website.edu");

CSS

CSS can be used to completely change the styles of the widget design. Every part of the widget has a relevant class that can be targeted with CSS. The default stylesheet alma_hours_widget.css can be used as a starting point for your widget's design.

<link rel="stylesheet" href="alma_hours_widget.css" />

JS

Creates the widget using AJAX to query the API script

<script src="alma_hours_widget.js"></script>

jQuery

The Alma Hours Widget requires jQuery to be loaded on the page where the widget is to be displayed.

PHP

A PHP script is used to query the REST API interface, cleanup/format the output and feedback the results as JSON. Caching can also be easily added at this layer to speed up loading time and reduce API requests to Ex Libris.

HTML

Each widget is added by adding a DIV tag with the class "alma_hours_widget".

Basic Widget (displays next 7 days of hours):

<div class="alma_hours_widget" data-library="MILLAR" data-title="Library Hours"></div>
  • The data-library and data-title attributes are required attributes.

data-library

The value for data-library can be found in Alma by navigating to the Fulfillment Configuration - Configuration Menu. In the "You are configuring:" dropdown menu, select the library for which you would like to create an Hours Widget. Then select "Opening Hours" under Library. Select the "Summary" tab to reveal the library's "Code". The value for the Library Code should be used for the data-library attribute to create a widget for that library.

Full Usage Example:

<!-- Alma Hours Widget CSS -->
<link rel="stylesheet" href="alma_hours_widget.css" />

<!-- jQuery Library -->
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- Alma Hours Widget JS -->
<script src="alma_hours_widget.js"></script>

<!-- Alma Hours Widget (next 7 days) -->
<div class="alma_hours_widget" data-library="MILLAR" data-title="Basic Hours"></div>

Optional HTML5 Attributes:

  • data-start-date – Used to set the start date for the widget
  • data-end-date – Used to set the end date for the widget
  • data-date-format – PHP standard date format options (e.g. "m/d/Y", "m/d/y", "m-d-y", etc…)
  • data-time-format – PHP standard time format options (e.g. "g:ia", "H:i:s", etc…)

These optional HTML5 attributes may be added to the DIV tag placeholder as seen in the following examples:

Custom Time/Date Formats:

<div class="alma_hours_widget" data-library="MILLAR" data-title="Custom Date/Time Format" data-date-format="m-d-y" data-time-format="H:i:s"></div>

Custom Date Range:

<div class="alma_hours_widget" data-library="MILLAR" data-title="Custom Date Range" data-start-date="2015-11-24" data-end-date="2015-12-05"></div>