Documentation
Documentation
Graphic_Data_Transfer_Tsv
in package
Class Graphic_Data_Transfer_Tsv.
Tags
Table of Contents
Constants
- EXISTING_HELP : mixed = 'The item on this site that this row updates: i...
- Help text of the existing_id column.
- FIELD_CLASSES : mixed = array('instance' => array('Graphic_Data_Instanc...
- Class holding each content type's field definitions.
- FILES : mixed = array('instance_type' => 'instance_types.tsv',...
- TSV file of each content type, in the order they are read.
- GRAPH_TYPES : mixed = array('Plotly bar graph', 'Plotly line graph (t...
- Interactive figure types a bulk import can build.
- ID_OFFSET : mixed = 1000000000
- Rows are given source IDs from here up, so they never match the ID of existing content that the rows link to.
- MAX_ERRORS : mixed = 200
- Stop listing problems after this many.
- MEDIA_PLACEHOLDER : mixed = 'https://graphic-data-bulk-import.invalid/media/'
- Stand-in address for a media file until it is added to the Media Library; the importer replaces it with the new address.
- NO_DATA_GRAPH_TYPES : mixed = array('Image Carousel', 'Image Comparison Slider')
- Interactive figure types that have no data file.
- PACKAGE_TYPE : mixed = 'bulk'
- Package type recorded for a converted bulk import.
- README_FILE : mixed = 'README.tsv'
- Reference file in the template.
- REQUIRED_FIELDS : mixed = array('instance' => array('instance_short_title...
- Fields that cannot be left blank (the edit screens refuse to save without them).
- SKIPPED_FIELDS : mixed = array('figure_interactive_args_rendered')
- Fields that are generated rather than imported.
- SOURCE_PREFIX : mixed = 'bulk-import:'
- Start of the source "site" recorded for a converted bulk import. The rest is a hash of the uploaded zip, so importing the same zip again is recognised as importing copies.
Properties
- $base : string
- Folder inside the zip that holds the TSV files ('' or ending in /).
- $columns : array<string, array<string|int, mixed>>
- Column definitions, by content type.
- $data_files : array<string|int, array<string|int, mixed>>
- Package figure data files.
- $errors : array<string|int, string>
- Problems that stop the import.
- $existing_terms : array<int, int>
- Existing term ID => package source ID.
- $files : array<string, string|array{path: string}>
- Files to write into the package: zip path => string content, or an array with the path of a local file.
- $headers : array<string, array<string, true>>
- Column names in each TSV file's header row, by content type.
- $local_links : array<string, int>
- Links to existing content: target key => post ID.
- $matches : array<string, array<int, int>>
- Source ID of the row that matches each existing item, by content type and the item's ID.
- $media : array<string|int, array<string|int, mixed>>
- Package media files.
- $media_sources : array<string, string>
- Media source (zip path or URL) => placeholder address.
- $next_id : int
- Next source ID.
- $posts : array<string|int, array<string|int, mixed>>
- Package posts.
- $references : array<string|int, array<string|int, mixed>>
- Links from package posts to existing content, with its title and slug.
- $refs : array<string, array<string, int>>
- Source ID of each row, by content type and ref.
- $render : array<string|int, int>
- Source IDs of the Figures whose saved figure is built after import.
- $rows : array<string, array<string|int, array<string|int, mixed>>>
- Rows by content type: line (record number), source ID and cells.
- $temp_files : array<string|int, string>
- Temporary files to delete.
- $terms : array<string|int, array<string|int, mixed>>
- Package terms.
- $warnings : array<string|int, string>
- Problems the import is shown with.
- $work_dir : string
- Folder for temporary files.
- $zip : ZipArchive|null
- Uploaded zip.
Methods
- convert() : true|WP_Error
- Convert a bulk import zip into a Content Transfer package.
- csv_to_json() : string
- Convert CSV to the JSON the Figure edit screen makes from an uploaded CSV file: a port of csvToJson() and formatJsonCompact() in admin/exopite-simple-options/fields/upload.php, giving the same text.
- get_columns() : array<string, array<string|int, mixed>>
- The columns of a content type's TSV file, in template order.
- get_readme_rows() : array<string|int, array<string|int, mixed>>
- Rows of README.tsv: the general rules, then every column of every file.
- get_site_key() : string
- This site as written in existing_id cells, for example "example.org/data".
- is_bulk_zip() : bool
- Whether a zip is a bulk import: it has no manifest.json and holds at least one of the TSV files.
- js_number() : string
- A number as JavaScript writes it (String( number )).
- js_trim() : string
- Trim whitespace as JavaScript's String.prototype.trim() does.
- parse_settings() : array<string, mixed>|null
- Decode interactive settings: the edit screen's array of [name, value] pairs, or an object of the same.
- to_tsv() : string
- Format rows as TSV, quoting cells that need it.
- write_template() : true|WP_Error
- Write the template zip: an empty TSV file per content type (header row only) and README.tsv describing every column.
- add_data_entry() : void
- Add a data file entry and its file.
- add_data_file() : array<string|int, mixed>|null
- Add a figure's data file to the package, as the Figure edit screen's upload does: a CSV file is kept and converted to JSON; a JSON file must have the structure the converter writes; a GeoJSON file is the figure's data as it is.
- add_existing_data() : array<string|int, mixed>|null
- Add the data files that an existing Figure uses, for a row that does not give new ones.
- add_media() : string
- Add a media file to the package (once, however many rows use it).
- assign_ids() : void
- Check every row's ref and give every row its source ID.
- build_post() : void
- Build a package post from a row.
- build_terms() : void
- Build the package terms from instance_types.tsv.
- cell() : string
- A cell's value: trimmed, with the escapes \n, \t and \\ turned into a line break, tab and backslash in text cells.
- check_links() : void
- Check a Scene's or Modal's info and media links: each one counted by its *_entries field needs its text and its URL (or, for media, its image).
- check_post() : void
- The checks the edit screens make when a post is saved.
- column() : array<string|int, mixed>
- A column definition.
- convert_value() : string
- Check and convert a cell into the value saved in the post's meta.
- describe_field() : array<string|int, mixed>
- Describe an edit screen field as a column.
- error() : void
- Record a problem that stops the import.
- extract() : string
- Copy a file out of the uploaded zip into a temporary file.
- find_base() : string|null
- Folder in the zip that holds the TSV files: the top level, or a single folder (as when a folder is zipped).
- find_by_slug() : int
- Find an item on this site by slug.
- finish_figure() : array<string|int, mixed>
- Add a figure's data file and check its interactive settings. A figure whose settings cannot be used is imported with its Status set to Draft, with a warning; one whose settings are good has its saved figure built after the import.
- get_column_help() : string
- Description of a column for README.tsv.
- get_fields() : array<string|int, array<string|int, mixed>>
- The edit screen field definitions of a content type, with tabs flattened.
- get_general_notes() : array<string|int, string>
- General rules, listed at the top of README.tsv.
- get_kept_value() : string
- A matched item's value for a column that the row leaves as it is.
- get_missing_columns() : array<string|int, string>
- Data columns used by bar and line graph settings that the data file does not have.
- get_stored_value() : string
- A column's value stored for an existing item.
- get_zip_path() : string
- A path inside a folder of the zip, or '' if it is not one.
- has_error() : bool
- Whether a problem has already been recorded for a cell, so that a cell whose value was rejected is not also reported as blank.
- is_chart_unchanged() : bool
- Whether a row leaves the chart of the Figure it matches as it is: it was drawn already, and its settings and data are the same.
- is_existing() : bool
- Whether an item of a type exists on this site.
- is_js_number() : bool
- Whether JavaScript's Number() reads text as a number (isNaN() is false).
- is_media_extra_column() : bool
- Whether a column name is <media column>_alt or <media column>_caption.
- is_same_image() : bool
- Whether an image cell holds the image that is stored: its address, or the exported file of its attachment (which may be stored resized).
- is_unchanged() : bool
- Whether a row leaves a column of the item it matches as it is: the column was left out of the file, or the cell holds what the Spreadsheets export writes for the item. The stored value is then kept exactly, rather than being cleaned, given its default or uploaded again.
- is_valid_data_json() : bool
- Whether decoded JSON has the structure of a figure data file (the Figure edit screen's validateJson()).
- keeps() : bool
- Whether a row takes a column from the item it matches: the column was left out of the file.
- match_row() : void
- Find the existing item that a row matches, and note it in the row.
- parse_csv_value() : string|float
- One CSV value as csvToJson() parses it: "NA" for missing values, a number (float) for numeric text, otherwise the text.
- read_header() : array<int, string>|null
- Check a header row.
- read_table() : void
- Read one TSV file into $rows.
- resolve_media_cell() : string
- Resolve an image cell.
- resolve_post_cell() : string
- Resolve a link to an Instance, Scene, Modal or page.
- resolve_term_cell() : string
- Resolve an Instance Type cell.
- sanitize() : mixed
- Clean a value the way the edit screen does when it saves the field.
- split_reference() : array{0: string, 1: string}
- Split a link cell into its kind and key. A value without a prefix is a ref when a row has it, otherwise an ID when it is a number.
- to_utf8() : string|null
- Text of a TSV file as UTF-8 without a byte order mark.
- write_package() : true|WP_Error
- Write the package: manifest.json, content.json, media and data files.
Constants
EXISTING_HELP
Help text of the existing_id column.
public
mixed
EXISTING_HELP
= 'The item on this site that this row updates: its ID, or <ID>@<site> as written by the Spreadsheets export, which is ignored on other sites. Blank: the item with the same slug, if there is one. The import screen asks whether to update matched items or import copies of them.'
FIELD_CLASSES
Class holding each content type's field definitions.
public
mixed
FIELD_CLASSES
= array('instance' => array('Graphic_Data_Instance', 'includes/admin-instance.php'), 'scene' => array('Graphic_Data_Scene', 'includes/admin-scene.php'), 'modal' => array('Graphic_Data_Modal', 'includes/admin-modal.php'), 'figure' => array('Graphic_Data_Figure', 'includes/admin-figure.php'))
FILES
TSV file of each content type, in the order they are read.
public
mixed
FILES
= array('instance_type' => 'instance_types.tsv', 'instance' => 'instances.tsv', 'scene' => 'scenes.tsv', 'modal' => 'modals.tsv', 'figure' => 'figures.tsv')
GRAPH_TYPES
Interactive figure types a bulk import can build.
public
mixed
GRAPH_TYPES
= array('Plotly bar graph', 'Plotly line graph (time series)', 'Tabulator table', 'Leaflet map', 'Image Carousel', 'Image Comparison Slider')
ID_OFFSET
Rows are given source IDs from here up, so they never match the ID of existing content that the rows link to.
public
mixed
ID_OFFSET
= 1000000000
MAX_ERRORS
Stop listing problems after this many.
public
mixed
MAX_ERRORS
= 200
MEDIA_PLACEHOLDER
Stand-in address for a media file until it is added to the Media Library; the importer replaces it with the new address.
public
mixed
MEDIA_PLACEHOLDER
= 'https://graphic-data-bulk-import.invalid/media/'
NO_DATA_GRAPH_TYPES
Interactive figure types that have no data file.
public
mixed
NO_DATA_GRAPH_TYPES
= array('Image Carousel', 'Image Comparison Slider')
PACKAGE_TYPE
Package type recorded for a converted bulk import.
public
mixed
PACKAGE_TYPE
= 'bulk'
README_FILE
Reference file in the template.
public
mixed
README_FILE
= 'README.tsv'
REQUIRED_FIELDS
Fields that cannot be left blank (the edit screens refuse to save without them).
public
mixed
REQUIRED_FIELDS
= array('instance' => array('instance_short_title', 'instance_slug'))
SKIPPED_FIELDS
Fields that are generated rather than imported.
public
mixed
SKIPPED_FIELDS
= array('figure_interactive_args_rendered')
SOURCE_PREFIX
Start of the source "site" recorded for a converted bulk import. The rest is a hash of the uploaded zip, so importing the same zip again is recognised as importing copies.
public
mixed
SOURCE_PREFIX
= 'bulk-import:'
Properties
$base
Folder inside the zip that holds the TSV files ('' or ending in /).
private
string
$base
= ''
$columns
Column definitions, by content type.
private
static array<string, array<string|int, mixed>>
$columns
= array()
$data_files
Package figure data files.
private
array<string|int, array<string|int, mixed>>
$data_files
= array()
$errors
Problems that stop the import.
private
array<string|int, string>
$errors
= array()
$existing_terms
Existing term ID => package source ID.
private
array<int, int>
$existing_terms
= array()
$files
Files to write into the package: zip path => string content, or an array with the path of a local file.
private
array<string, string|array{path: string}>
$files
= array()
$headers
Column names in each TSV file's header row, by content type.
private
array<string, array<string, true>>
$headers
= array()
$local_links
Links to existing content: target key => post ID.
private
array<string, int>
$local_links
= array()
$matches
Source ID of the row that matches each existing item, by content type and the item's ID.
private
array<string, array<int, int>>
$matches
= array()
$media
Package media files.
private
array<string|int, array<string|int, mixed>>
$media
= array()
$media_sources
Media source (zip path or URL) => placeholder address.
private
array<string, string>
$media_sources
= array()
$next_id
Next source ID.
private
int
$next_id
= self::ID_OFFSET
$posts
Package posts.
private
array<string|int, array<string|int, mixed>>
$posts
= array()
$references
Links from package posts to existing content, with its title and slug.
private
array<string|int, array<string|int, mixed>>
$references
= array()
$refs
Source ID of each row, by content type and ref.
private
array<string, array<string, int>>
$refs
= array()
$render
Source IDs of the Figures whose saved figure is built after import.
private
array<string|int, int>
$render
= array()
$rows
Rows by content type: line (record number), source ID and cells.
private
array<string, array<string|int, array<string|int, mixed>>>
$rows
= array()
$temp_files
Temporary files to delete.
private
array<string|int, string>
$temp_files
= array()
$terms
Package terms.
private
array<string|int, array<string|int, mixed>>
$terms
= array()
$warnings
Problems the import is shown with.
private
array<string|int, string>
$warnings
= array()
$work_dir
Folder for temporary files.
private
string
$work_dir
= ''
$zip
Uploaded zip.
private
ZipArchive|null
$zip
= \null
Methods
convert()
Convert a bulk import zip into a Content Transfer package.
public
convert(string $source_path, string $package_path) : true|WP_Error
Parameters
- $source_path : string
-
Uploaded zip.
- $package_path : string
-
Package to write.
Return values
true|WP_Error —The error's data holds every problem found ('errors').
csv_to_json()
Convert CSV to the JSON the Figure edit screen makes from an uploaded CSV file: a port of csvToJson() and formatJsonCompact() in admin/exopite-simple-options/fields/upload.php, giving the same text.
public
static csv_to_json(string $csv) : string
Lines before the header row (the first line whose cells are all filled in) become metadata. Values are split on commas without quoting; blank, NA, NaN and "null" become "NA"; numbers become numbers.
Parameters
- $csv : string
-
CSV text.
Return values
string —JSON text (not valid JSON if a value holds a double quote or backslash, as on the edit screen), or '' for an empty file, which the edit screen rejects.
get_columns()
The columns of a content type's TSV file, in template order.
public
static get_columns(string $type) : array<string, array<string|int, mixed>>
Each column has a kind ('ref', 'title', 'slug', 'text', 'html', 'code', 'number', 'color', 'choice', 'post', 'term', 'tab', 'media', 'data', 'settings' or 'existing'), a label, help text, whether it is required, its allowed values, its default, the post type it links to, the fieldset it belongs to and the edit screen's field definition.
Parameters
- $type : string
-
Content type: a key of FILES.
Return values
array<string, array<string|int, mixed>>get_readme_rows()
Rows of README.tsv: the general rules, then every column of every file.
public
static get_readme_rows() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>>get_site_key()
This site as written in existing_id cells, for example "example.org/data".
public
static get_site_key() : string
Return values
stringis_bulk_zip()
Whether a zip is a bulk import: it has no manifest.json and holds at least one of the TSV files.
public
static is_bulk_zip(string $path) : bool
Parameters
- $path : string
-
Zip path.
Return values
booljs_number()
A number as JavaScript writes it (String( number )).
public
static js_number(float $number) : string
Parameters
- $number : float
-
Number.
Return values
stringjs_trim()
Trim whitespace as JavaScript's String.prototype.trim() does.
public
static js_trim(string $text) : string
Parameters
- $text : string
-
Text.
Return values
stringparse_settings()
Decode interactive settings: the edit screen's array of [name, value] pairs, or an object of the same.
public
static parse_settings(string $raw) : array<string, mixed>|null
Parameters
- $raw : string
-
Settings JSON.
Return values
array<string, mixed>|null —Settings by name, or null if invalid.
to_tsv()
Format rows as TSV, quoting cells that need it.
public
static to_tsv(array<string|int, array<string|int, mixed>> $rows) : string
Parameters
- $rows : array<string|int, array<string|int, mixed>>
-
Rows of cells.
Return values
stringwrite_template()
Write the template zip: an empty TSV file per content type (header row only) and README.tsv describing every column.
public
static write_template(string $path) : true|WP_Error
Parameters
- $path : string
-
Zip path.
Return values
true|WP_Erroradd_data_entry()
Add a data file entry and its file.
private
add_data_entry(int $source_id, string $field, string $zip_name, string $contents) : void
Parameters
- $source_id : int
-
Source ID of the figure.
- $field : string
-
Meta key holding the file's path.
- $zip_name : string
-
Path in the package.
- $contents : string
-
File contents.
add_data_file()
Add a figure's data file to the package, as the Figure edit screen's upload does: a CSV file is kept and converted to JSON; a JSON file must have the structure the converter writes; a GeoJSON file is the figure's data as it is.
private
add_data_file(string $value, int $source_id, string $where) : array<string|int, mixed>|null
Parameters
- $value : string
-
Cell value (data/
). - $source_id : int
-
Source ID of the figure.
- $where : string
-
Location for messages.
Return values
array<string|int, mixed>|null —Meta to save and the data's column names, or null.
add_existing_data()
Add the data files that an existing Figure uses, for a row that does not give new ones.
private
add_existing_data(int $figure_id, int $source_id) : array<string|int, mixed>|null
Parameters
- $figure_id : int
-
Existing Figure.
- $source_id : int
-
Source ID of the row.
Return values
array<string|int, mixed>|null —As add_data_file(), or null if it has no data.
add_media()
Add a media file to the package (once, however many rows use it).
private
add_media(string $url, string $path, string $alt, string $caption, string $where, string $name) : string
Parameters
- $url : string
-
Address to download from, or ''.
- $path : string
-
Path inside the zip, or ''.
- $alt : string
-
Alt text.
- $caption : string
-
Caption.
- $where : string
-
Location for messages.
- $name : string
-
Column name.
Return values
string —Placeholder address.
assign_ids()
Check every row's ref and give every row its source ID.
private
assign_ids() : void
build_post()
Build a package post from a row.
private
build_post(string $type, array<string|int, mixed> $row) : void
Parameters
- $type : string
-
Content type.
- $row : array<string|int, mixed>
-
Row.
build_terms()
Build the package terms from instance_types.tsv.
private
build_terms() : void
cell()
A cell's value: trimmed, with the escapes \n, \t and \\ turned into a line break, tab and backslash in text cells.
private
cell(array<string|int, mixed> $row, string $name, array<string|int, mixed> $column) : string
Parameters
- $row : array<string|int, mixed>
-
Row.
- $name : string
-
Column name.
- $column : array<string|int, mixed>
-
Column definition.
Return values
stringcheck_links()
Check a Scene's or Modal's info and media links: each one counted by its *_entries field needs its text and its URL (or, for media, its image).
private
check_links(string $type, callable $value, string $where) : void
Parameters
- $type : string
-
'scene' or 'modal'.
- $value : callable
-
Reads a meta value.
- $where : string
-
Location for messages.
check_post()
The checks the edit screens make when a post is saved.
private
check_post(array<string|int, mixed> $entry, string $where) : void
Parameters
- $entry : array<string|int, mixed>
-
Package post.
- $where : string
-
Location for messages.
column()
A column definition.
private
static column(string $kind, string $label, string $help[, bool $required = false ]) : array<string|int, mixed>
Parameters
- $kind : string
-
Kind.
- $label : string
-
Label.
- $help : string
-
Help text.
- $required : bool = false
-
Whether the cell must be filled in.
Return values
array<string|int, mixed>convert_value()
Check and convert a cell into the value saved in the post's meta.
private
convert_value(string $value, string $name, array<string|int, mixed> $column, array<string|int, mixed> $row, string $where) : string
Parameters
- $value : string
-
Cell value.
- $name : string
-
Column name.
- $column : array<string|int, mixed>
-
Column definition.
- $row : array<string|int, mixed>
-
Row.
- $where : string
-
Location for messages.
Return values
stringdescribe_field()
Describe an edit screen field as a column.
private
static describe_field(array<string|int, mixed> $field, string $type, string $prefix) : array<string|int, mixed>
Parameters
- $field : array<string|int, mixed>
-
Field definition.
- $type : string
-
Content type.
- $prefix : string
-
Label prefix (the fieldset's title).
Return values
array<string|int, mixed>error()
Record a problem that stops the import.
private
error(string $message) : void
Parameters
- $message : string
-
Problem.
extract()
Copy a file out of the uploaded zip into a temporary file.
private
extract(string $path) : string
Parameters
- $path : string
-
Path inside the zip, relative to the TSV folder.
Return values
string —Temporary file.
find_base()
Folder in the zip that holds the TSV files: the top level, or a single folder (as when a folder is zipped).
private
static find_base(ZipArchive $zip) : string|null
Parameters
- $zip : ZipArchive
-
Zip.
Return values
string|null —Folder ('' or ending in /), or null if there are no TSV files.
find_by_slug()
Find an item on this site by slug.
private
find_by_slug(string $type, string $slug) : int
Parameters
- $type : string
-
Content type.
- $slug : string
-
Slug.
Return values
int —Post or term ID, or 0.
finish_figure()
Add a figure's data file and check its interactive settings. A figure whose settings cannot be used is imported with its Status set to Draft, with a warning; one whose settings are good has its saved figure built after the import.
private
finish_figure(array<string|int, mixed> $entry, array<string|int, mixed>|null $data, string $where) : array<string|int, mixed>
Parameters
- $entry : array<string|int, mixed>
-
Package post.
- $data : array<string|int, mixed>|null
-
Data file from add_data_file().
- $where : string
-
Location for messages.
Return values
array<string|int, mixed> —Package post.
get_column_help()
Description of a column for README.tsv.
private
static get_column_help(string $name, array<string|int, mixed> $column) : string
Parameters
- $name : string
-
Column name.
- $column : array<string|int, mixed>
-
Column definition.
Return values
stringget_fields()
The edit screen field definitions of a content type, with tabs flattened.
private
static get_fields(string $type) : array<string|int, array<string|int, mixed>>
Parameters
- $type : string
-
Content type.
Return values
array<string|int, array<string|int, mixed>>get_general_notes()
General rules, listed at the top of README.tsv.
private
static get_general_notes() : array<string|int, string>
Return values
array<string|int, string>get_kept_value()
A matched item's value for a column that the row leaves as it is.
private
get_kept_value(int $post_id, string $name, array<string|int, mixed> $column, array<string|int, mixed> $row, string $where) : string
Parameters
- $post_id : int
-
Existing post.
- $name : string
-
Column name.
- $column : array<string|int, mixed>
-
Column definition.
- $row : array<string|int, mixed>
-
Row.
- $where : string
-
Location for messages.
Return values
stringget_missing_columns()
Data columns used by bar and line graph settings that the data file does not have.
private
static get_missing_columns(array<string, mixed> $settings, array<string|int, string> $columns) : array<string|int, string>
Parameters
- $settings : array<string, mixed>
-
Settings.
- $columns : array<string|int, string>
-
Data columns.
Return values
array<string|int, string>get_stored_value()
A column's value stored for an existing item.
private
get_stored_value(int $post_id, string $name, array<string|int, mixed> $column) : string
Parameters
- $post_id : int
-
Existing post.
- $name : string
-
Column name.
- $column : array<string|int, mixed>
-
Column definition.
Return values
stringget_zip_path()
A path inside a folder of the zip, or '' if it is not one.
private
get_zip_path(string $value, string $folder) : string
Parameters
- $value : string
-
Cell value.
- $folder : string
-
'media' or 'data'.
Return values
stringhas_error()
Whether a problem has already been recorded for a cell, so that a cell whose value was rejected is not also reported as blank.
private
has_error(string $where, string $name) : bool
Parameters
- $where : string
-
Location (file and row).
- $name : string
-
Column name.
Return values
boolis_chart_unchanged()
Whether a row leaves the chart of the Figure it matches as it is: it was drawn already, and its settings and data are the same.
private
is_chart_unchanged(array<string|int, mixed> $entry) : bool
Parameters
- $entry : array<string|int, mixed>
-
Package post.
Return values
boolis_existing()
Whether an item of a type exists on this site.
private
is_existing(string $type, int $id) : bool
Parameters
- $type : string
-
Content type.
- $id : int
-
Post or term ID.
Return values
boolis_js_number()
Whether JavaScript's Number() reads text as a number (isNaN() is false).
private
static is_js_number(string $value) : bool
Parameters
- $value : string
-
Trimmed, non-empty text.
Return values
boolis_media_extra_column()
Whether a column name is <media column>_alt or <media column>_caption.
private
is_media_extra_column(string $name, array<string|int, mixed> $columns) : bool
Parameters
- $name : string
-
Column name.
- $columns : array<string|int, mixed>
-
Column definitions.
Return values
boolis_same_image()
Whether an image cell holds the image that is stored: its address, or the exported file of its attachment (which may be stored resized).
private
is_same_image(string $value, string $stored) : bool
Parameters
- $value : string
-
Cell value.
- $stored : string
-
Stored address.
Return values
boolis_unchanged()
Whether a row leaves a column of the item it matches as it is: the column was left out of the file, or the cell holds what the Spreadsheets export writes for the item. The stored value is then kept exactly, rather than being cleaned, given its default or uploaded again.
private
is_unchanged(int $post_id, string $type, array<string|int, mixed> $row, string $name, array<string|int, mixed> $column, string $value) : bool
Parameters
- $post_id : int
-
Existing post.
- $type : string
-
Content type.
- $row : array<string|int, mixed>
-
Row.
- $name : string
-
Column name.
- $column : array<string|int, mixed>
-
Column definition.
- $value : string
-
Cell value.
Return values
boolis_valid_data_json()
Whether decoded JSON has the structure of a figure data file (the Figure edit screen's validateJson()).
private
static is_valid_data_json(mixed $data) : bool
Parameters
- $data : mixed
-
Decoded JSON.
Return values
boolkeeps()
Whether a row takes a column from the item it matches: the column was left out of the file.
private
keeps(string $type, array<string|int, mixed> $row, string $name) : bool
Parameters
- $type : string
-
Content type.
- $row : array<string|int, mixed>
-
Row.
- $name : string
-
Column name.
Return values
boolmatch_row()
Find the existing item that a row matches, and note it in the row.
private
match_row(string $type, int $index) : void
Parameters
- $type : string
-
Content type.
- $index : int
-
Index of the row.
parse_csv_value()
One CSV value as csvToJson() parses it: "NA" for missing values, a number (float) for numeric text, otherwise the text.
private
static parse_csv_value(string $value) : string|float
Parameters
- $value : string
-
Trimmed value.
Return values
string|floatread_header()
Check a header row.
private
read_header(array<string|int, mixed> $cells, array<string|int, mixed> $columns, string $file) : array<int, string>|null
Parameters
- $cells : array<string|int, mixed>
-
Header cells.
- $columns : array<string|int, mixed>
-
Column definitions.
- $file : string
-
File name.
Return values
array<int, string>|null —Column name by position ('' to skip), or null if the header is unusable.
read_table()
Read one TSV file into $rows.
private
read_table(string $type) : void
Parameters
- $type : string
-
Content type.
resolve_media_cell()
Resolve an image cell.
private
resolve_media_cell(string $value, string $name, array<string|int, mixed> $row, string $where) : string
Parameters
- $value : string
-
Cell value.
- $name : string
-
Column name.
- $row : array<string|int, mixed>
-
Row.
- $where : string
-
Location for messages.
Return values
string —Address of the image (a placeholder for files added by the import).
resolve_post_cell()
Resolve a link to an Instance, Scene, Modal or page.
private
resolve_post_cell(string $value, string $target_type, int $source_id, string $name, string $where) : string
Parameters
- $value : string
-
Cell value.
- $target_type : string
-
Post type linked to.
- $source_id : int
-
Source ID of the row.
- $name : string
-
Column name.
- $where : string
-
Location for messages.
Return values
string —Source ID of a row, ID of existing content, or ''.
resolve_term_cell()
Resolve an Instance Type cell.
private
resolve_term_cell(string $value, string $where) : string
Parameters
- $value : string
-
Cell value.
- $where : string
-
Location for messages.
Return values
string —Source ID of the package term, or ''.
sanitize()
Clean a value the way the edit screen does when it saves the field.
private
sanitize(array<string|int, mixed> $field, string $value) : mixed
Parameters
- $field : array<string|int, mixed>
-
Field definition.
- $value : string
-
Value.
split_reference()
Split a link cell into its kind and key. A value without a prefix is a ref when a row has it, otherwise an ID when it is a number.
private
split_reference(string $value, array<string, int> $refs) : array{0: string, 1: string}
Parameters
- $value : string
-
Cell value.
- $refs : array<string, int>
-
Refs of the rows that can be linked to.
Return values
array{0: string, 1: string} —Kind ('ref', 'id', 'slug' or '') and key.
to_utf8()
Text of a TSV file as UTF-8 without a byte order mark.
private
to_utf8(string $raw, string $file) : string|null
Parameters
- $raw : string
-
File contents.
- $file : string
-
File name.
Return values
string|null —Null (with an error recorded) if the file is not UTF-8 or UTF-16 text.
write_package()
Write the package: manifest.json, content.json, media and data files.
private
write_package(string $path, string $hash) : true|WP_Error
Parameters
- $path : string
-
Package path.
- $hash : string
-
Hash of the uploaded zip.